Some fixes to error handling.