Some more tests and a few bug fixes