Refactor trajectory grouping and randomize group colors.