Code Refactoring + Test Cases