Refactoring: re-organize the code.