Added state change logic.