make save/restore settings less repetitive

Hi. Saw your code, and decided that the whole save/restore settings part could be made a little less repetitive. Herewith my patch. I haven’t actually tested it; please let me know if you have any questions about how it works.