added some next state logic