Added global error handling