public static Cons standardizeQueryTree(Stella_Object iovariables, Stella_Object querybody, Cons externalvariables) {
    if (iovariables == null) {
      iovariables = Stella.NIL;
    }
    else if (!Stella_Object.consP(iovariables)) {
      iovariables = Cons.consList(Cons.cons(iovariables, Stella.NIL));
    }
    { Cons standardizedtree = null;
      Cons allvariables = ((Cons)(iovariables));

      { Stella_Object v = null;
        Cons iter000 = externalvariables.reverse();

        for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
          v = iter000.value;
          allvariables = Cons.cons(v, allvariables);
        }
      }
      if (querybody == null) {
        querybody = Logic.SYM_STELLA_TRUE;
      }
      if (allvariables == Stella.NIL) {
        standardizedtree = Cons.list$(Cons.cons(Logic.SYM_LOGIC_KAPPA, Cons.cons(Stella.NIL, Cons.cons(querybody, Cons.cons(Stella.NIL, Stella.NIL)))));
      }
      else {
        standardizedtree = Cons.list$(Cons.cons(Logic.SYM_STELLA_EXISTS, Cons.cons(allvariables, Cons.cons(Cons.cons(querybody, Stella.NIL), Stella.NIL))));
      }
      standardizedtree = ((Cons)(Logic.standardizeLogicalParseTree(standardizedtree)));
      standardizedtree.firstSetter(Logic.SYM_LOGIC_KAPPA);
      return (standardizedtree);
    }
  }