added error handling for data fetching