More refactorings.
Tidied up a few tests.