Add a few more tests and start some refactoring.