Fixed bug in locking