Refactoring + unit tests