Added storing and restoring of window state.