solution for exercise 4.1