fix some /analyze warnings
preserve the view state of background states when closing the last window