added global error handling