Refactoring and more tests.