Clean up the error handling a bit