Add locking code