Lots of tests and little fixes.