Bugfixes and tests.