Added retries to the query method