Optimized querying by using single query and using asynch functions