refactoring: remove code duplication