solution to exercise 9