Chapter 4 exercises done.

Bonus points for writing unit tests!