State discontinuity after switching Error

Thanks Kris for your suggestion