Move the lock up
Nicholas still reports issues with the lock in the else, though logically that should be impossible.