Modified grouping of states and calculating distinct state