public static Keyword collectMembersSpecialist(ControlFrame frame, Keyword lastmove) {
    { Proposition proposition = frame.proposition;
      Stella_Object collectionarg = (proposition.arguments.theArray)[0];
      Stella_Object collectionvalue = Logic.argumentBoundTo(collectionarg);
      Stella_Object listarg = (proposition.arguments.theArray)[1];
      boolean listP = false;
      boolean uniqueP = true;
      List members = null;
      Stella_Object result = null;

      lastmove = lastmove;
      if (collectionvalue == null) {
        return (Logic.KWD_TERMINAL_FAILURE);
      }
      { GeneralizedSymbol testValue000 = proposition.operator;

        if (testValue000 == Logic.SGT_PL_KERNEL_KB_COLLECT_INTO_LIST) {
          listP = true;
          uniqueP = false;
        }
        else if (testValue000 == Logic.SGT_PL_KERNEL_KB_COLLECT_INTO_ORDERED_SET) {
          listP = true;
        }
        else {
        }
      }
      if ((((Iterator)(KeyValueList.dynamicSlotValue(frame.dynamicSlots, Logic.SYM_STELLA_ITERATOR, null))) == null) &&
          (((Logic.enumeratedSetP(collectionvalue) &&
          (!listP)) ||
          (Logic.enumeratedListP(collectionvalue) &&
           (!uniqueP))) &&
           (((LogicObject)(collectionvalue)).variableValueInverse() == Stella.NIL))) {
        result = collectionvalue;
      }
      else if (((Iterator)(KeyValueList.dynamicSlotValue(frame.dynamicSlots, Logic.SYM_STELLA_ITERATOR, null))) == null) {
        { Surrogate testValue001 = Stella_Object.safePrimaryType(collectionvalue);

          if (Surrogate.subtypeOfP(testValue001, Logic.SGT_STELLA_COLLECTION)) {
            { Collection collectionvalue000 = ((Collection)(collectionvalue));

              members = Logic.assertedCollectionMembers(collectionvalue000, false);
              if (members == null) {
                return (Logic.KWD_TERMINAL_FAILURE);
              }
            }
          }
          else if (Surrogate.subtypeOfP(testValue001, Logic.SGT_LOGIC_SKOLEM)) {
            { Skolem collectionvalue000 = ((Skolem)(collectionvalue));

              members = Logic.assertedCollectionMembers(collectionvalue000, false);
              if (members == null) {
                return (Logic.KWD_TERMINAL_FAILURE);
              }
            }
          }
          else if (Surrogate.subtypeOfP(testValue001, Logic.SGT_LOGIC_DESCRIPTION)) {
            { Description collectionvalue000 = ((Description)(collectionvalue));

              { boolean testValue002 = false;

                testValue002 = ((Vector)(KeyValueList.dynamicSlotValue(collectionvalue000.dynamicSlots, Logic.SYM_LOGIC_EXTERNAL_VARIABLES, null))) != null;
                if (testValue002) {
                  { boolean foundP000 = false;

                    { PatternVariable v = null;
                      Vector vector000 = ((Vector)(KeyValueList.dynamicSlotValue(collectionvalue000.dynamicSlots, Logic.SYM_LOGIC_EXTERNAL_VARIABLES, null)));
                      int index000 = 0;
                      int length000 = vector000.length();

                      loop000 : for (;index000 < length000; index000 = index000 + 1) {
                        v = ((PatternVariable)((vector000.theArray)[index000]));
                        if (!(Logic.argumentBoundTo(v) != null)) {
                          foundP000 = true;
                          break loop000;
                        }
                      }
                    }
                    testValue002 = foundP000;
                  }
                }
                if (testValue002) {
                  return (Logic.KWD_TERMINAL_FAILURE);
                }
              }
              if (Description.inferableP(collectionvalue000)) {
                ControlFrame.createCollectDescriptionExtensionFrame(frame, collectionvalue000);
                KeyValueList.setDynamicSlotValue(frame.dynamicSlots, Logic.SYM_STELLA_ITERATOR, Logic.EMPTY_PROPOSITIONS_ITERATOR, null);
                return (Logic.KWD_MOVE_DOWN);
              }
              else {
                members = Logic.assertedCollectionMembers(collectionvalue000, false);
                if (members == null) {
                  return (Logic.KWD_TERMINAL_FAILURE);
                }
                uniqueP = false;
              }
            }
          }
          else {
            return (Logic.KWD_FAILURE);
          }
        }
      }
      else {
        if (frame.down == null) {
          return (Logic.KWD_FAILURE);
        }
        { ControlFrame patternframe = frame.down;

          members = patternframe.patternRecord.collectionList.reverse();
          ControlFrame.popFramesUpTo(patternframe);
          if (((Keyword)(KeyValueList.dynamicSlotValue(patternframe.dynamicSlots, Logic.SYM_LOGIC_INFERENCE_CUTOFF_REASON, null))) != null) {
            return (Logic.KWD_FAILURE);
          }
        }
      }
      if (result == null) {
        if (uniqueP) {
          members = (Stella_Object.consP(members.first()) ? members.removeDuplicatesEqual() : ((List)(members.removeDuplicates())));
        }
        result = (listP ? Logic.createLogicalList(members) : Logic.createEnumeratedSet(members));
      }
      { Keyword success = Logic.selectTestResult(Logic.bindArgumentToValueP(listarg, result, true), true, frame);

        if (((Boolean)(Logic.$RECORD_JUSTIFICATIONSp$.get())).booleanValue() &&
            (!(success == Logic.KWD_TERMINAL_FAILURE))) {
          { Justification self001 = Justification.newJustification();

            self001.inferenceRule = Logic.KWD_COLLECT_MEMBERS;
            { Justification justification = self001;
              Justification antecedents = ((frame.result != null) ? ((Justification)(KeyValueList.dynamicSlotValue(frame.result.dynamicSlots, Logic.SYM_LOGIC_JUSTIFICATION, null))) : ((Justification)(null)));

              if (antecedents != null) {
                justification.antecedents = Cons.cons(antecedents, Stella.NIL);
              }
              ControlFrame.recordGoalJustification(frame, justification);
            }
          }
        }
        return (success);
      }
    }
  }