adding more code from the book