Updated answer for exercise 2