adding tests, refactoring