added getNextState to flag
clean up