Move locking logic to its own class