More tests. Code tidyup.