Add tests for unlocking and minor bug fix