Refactoring + unittesting