add state handling logic