Added in some error checking.

It isn't the world's fanciest error checking, but it gets the job done so we're not raising bare Exceptions.