Complete overhaul of the locking mechanism.
minor fix