code from the o'reilly book with the same name