exercises 1-4 for chapter 16

This was a nice opportunity to use `state` again :)