Committing working version of exercise 9 from chapter 7.