Solution to exercise 2