remove some locks, adjust function placement