First version of Chapter 4 code.