Second rewrite of locking mechanism.