changed state logic a bit