updated global error handling function