add code from book website http://www.cs.nott.ac.uk/~gmh/book.html