reduced code redundancy by separating between filtering and states generation step