code cleanup, bug fixes, and the option of making the lock not upgradable (to prevent deadlock)