Chapter 3 exercise 2 and fixes to previous exercises