I think you have over-complicated this unnecessarily. I don't see why you need all those loops and all those arrays. You should be able to do it with one loop/one array.

Show us your group naming standard so we can determine the AScan() bit. Include a sample dump of GetGroups().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.