Refactoring + tests