more work on the book

keep on trucking, made some revisions to previous code to make it
cleaner and to add comments for my own reference.