writing, fixing tests and refactoring