Now saves the state on window close