just the code from chapter 6.4
exercise 5