Added checking the current state id and the new state id in changeState().