Various fixes and improvements. More tests.
100% test coverage.