Refactored duplicate code
Comment my reasoning