fixed subgroups and added sorting