Lots of Unit tests + some refactoring

You should watch my repo, merging your changes was a major PITA.

https://github.com/jklepp-tgm/dLock/commit/ac5a4930d3849802151697e685b0d3080b4ebf62