Refactored: removed code duplication