Solved exercises 40 - 49 from chapter 6