Refactoring + more test cases