much faster query graph without recursion