solution for exercise 6