script from Hadley Wickham's book with some comments and additions