Move complete locking logic to locking.go