Begin refactoring and adding more tests