simpler risort(groups)