A bit of refactoring.
More tests.