chapter 15 refactored and fixed errors