started writing tests and refactoring