fix bug in primal query creation