Adding generic error handling