Improved Chapter 3 exercise 3-3