Changes to make the code a little more robust

These are mostly changes to make the code a little more robust when handling errors.

The test framework as it stands makes this kind of hard to write tests for, but I did test this with some real code that runs tests using Sauce Labs, and it fixed a number of problems I was seeing.

I've based this off the dist-zilla branch, which appears to be branch which the latest release is from. It'd be nice if that became master instead. Also, it'd be great if you used the @Git plugin bundle to tag releases.