more tests and a couple of bug fixes