working on tests and refactoring