Stand-alone #61 commits

These are changes extracted from #61. Each commit is stand-alone, but all are
related to #61. Commits 1 and 2 are not required for #61, they are for testing,
but commits 3, 4 and 5 are. Commit 6 is not required but is perferable, see #83.