That's great! I didn't know the exact function names or syntax off the top of my head but I'm glad you were able to follow it and implement your own.
If you can, upload a clip to youtube. I love watching that kind of stuff where units make a descission individually and yet it results in group organization.
EDIT: you said it works, but i realized a small mistake i made. instead of "others = g" i meant to put others = copyofunitgroup(g). theres some function which makes a copy of a group whereas i think "=" just passes a reference to the same group