added gropping logic