improvements to the locking function