better state detection