Refactored code duplication