Bugfixes and more tests.