Small refactoring to the lock check logic. Added comments.