Solution to exercise 6