Listing 9.27. Tests now pass.