added all code up to end of chapter 12