improve solution for exercise 5