New code from chapter4. Almost done.
Final chapter 4 code.