Task 1-3, refactored code