Adding chapter 12 code
Various minor edits