Refactor objects

I hope I haven't broken anything. Anyone wish to confirm this?
ecx should be changed to groupIndex for all of the below code as it is used for assigning the groupIndex if it is unknown.