Some fixes for error handling