Better handling of state save/restore when switching tabs.