Multiple fixes to lock handling