Refactoring + additional tests