Refactoring and tests.