Second attempt at fixing saving settings on shutdown.
Fix previous commit.