Method that groups single elements into groups