Exercise 4.2 solution.