Refactoring + new tests