More tests and tidy-ups