Tested locking code