Code from the book, starting from the Chapter 13