Use deferred unlock to release lock even if errors occur
Merge pull request #1 from drevell/defer_unlock

Use deferred unlock to release lock even if errors occur