Refactor locking of pipeline