Solution for exercise 5