added error handling and caching