Solution to exercise 8