Refactored to remove repetitions