Listing 5.18 modified