Fix removegroups and remove duplicates.