updated code for Exercise 9.2