generic error handling improved