continuing work on chapter 9. refactored a bit of code along the way.