Cleaner handleing of 500 errors.

Just some code changes I made while mucking around in _handle_500.