Implementing exercise 4.2-6