Save app state on exit and restore on load (attempt 2)