refactoring: reduce duplicated code