Merge "Update code to avoid nested usage of locks." into main