AI-684 improved awkward locking code