refactor chapter 6 exercises