Better error handling

I suspect what I had before didn't make any sense.