Filled out more code from book.