Fix generateSubqueries method.