add code to chapters 3 - 7