Added locks/unlocks to critical sections