Added state update logic.