Refactor locking into its own header