better state handling