added initial code from sample code in the book
additional code from book