Add tests. Tidy-ups.