Add more tests and bugfixes.