More tests, refactoring.