Refactoring and writing tests.