refactoring legacy code example