Completed R&R task 5. Improves code of Task 1 (second attempt)