fix bugs for subqueries / waiting queries