refactor locking scoping