Simplify error-handling code

Thanks to @jdfreder for this change.