Refactored code, followed DRY principles