Improved test coverage
Bugfixes for everything found by unit tests