Merging together pull requests #12, #13 and #14

I've merged together pull requests #12, #13 and #14 and resolved all the resulting conflicts as things diverged a bit between each of them.