refactoring: code duplication eliminated