some code cleanup, working on chapter 4...
finished first pass of ch4