Cleaning up the error handling somewhat.