Some more tests and lots of bugfixes.