Finished algorithm to display groups.