Bugfixes and test cleanup.