Calling aaApi_CreateReferenceInformation2 to add to existing Logical Set.

We have a custom module that allows users to either create or modify a Logical Set by letting them select a parent document and identify others as child references.  When creating the Logical Set, it will first execute:
iReturn = aaApi_CreateLSet(iSetID, iParentProjID, iParentDocID, iChildProjID, iChildDocID, AADMS_SETMEM_REF, AADMS_SETMEM_COPY, iCurrentMemberID);
and then
iReturn = aaApi_CreateReferenceInformation2(iCurrentMemberID, gParentDocGuid, 0, gChildDocGuid, 0, AADMS_FTYPE_DWG, 99, AAREFINFO_REFERENCE_HAS_COPIED + AAREFINFO_IGNORE_IF_NESTED);

Subsequent children are added with:
iReturn = aaApi_AddLSetMember(iCurrentSetID, iChildProjID, iChildDocID, AADMS_SETMEM_REF, AADMS_SETMEM_COPY, iCurrentMemberID);
and then the same call to aaApi_CreateReferenceInformation2.

If a Logical Set is being modified, it first gets the SetID and then adds the new child using the calls to aaApi_AddLSetMember and then aaApi_CreateReferenceInformation2.  In every case where aaApi_CreateReferenceInformation2 is called, the first parameter "refElemId" (as its referred to in the documentation) is set to the Set Member ID of the child Member.  (It's apparent from the history of the code that what this value should be was uncertain, and that using the MemberID was something that was tried and appears to have been working in testing.)

In many, if not most cases, this works fine.  However, we are beginning to see some cases where adding a member to an existing Logical Set is causing the Document's "Set->Show Reference" command to only list the newly added Member.  In those cases, removing that new Member using aaApi_DeleteSetMember with the same SetID value will then cause the "Set->Show References" command to display all of the other children.

I've tried to figure out what the "refElemId" parameter should be set to for aaApi_CreateReferenceInformation2, but can't figure it out from the documentation.  Is that value the problem?  Is it any of the flags that are being set?  Since the results are inconsistent, it's been impossible for me to isolate, but I can't find any examples of how this should be done.

This only happens when adding a child to a previously existing Logical Set.  A work-around I discovered was that we can first remove every child from the existing Logical Set, which will then cause the parent to no longer be a Set document after the last child is removed.  Then we recreate it by making all of the same calls and adding all of the children, including the new one, into the Set.  Functionally, this should be no different (the new child is still being added last), but it avoids the problem.  The downside is that it can be noticeably slower if we're adding to a Set that already has a lot of children.