Fix a bunch of improper error handling.