refactor locking