refactoring + tests