Fixes #9. Most of the edits are pretty hacky.
Note that we are now going forward with a refactor to make all this a
bit easier.