Fix lock/unlock bug

In some situations, a lock was acquired but then never released.
Merge pull request #95 from mmorearty/fix-locking-bug

Fix lock/unlock bug