refactored locking in several modules