Ex 5.1: Recycled code from exercise 1.
Ex 5.3: Fixed a typo.