Listing 10.13 with all tests passing.