implemented group counting and group removal