Exercise 12.1 and code fixes