Some fixes to the error handling