refactoring remaining from chapter 5