fix state saving. fix new window issue