Bugfixes and test optimizations. tests are passing.