Add tests.
Refactoring.