Removing duplicate code after refactoring