Solution for exercise 2