Refactoring + unittests