start writing tests and refactoring