refactor some tests and add code from chapter 9 exercises