Cleaner locking code