solution to Exercise 5