Refactor setting save/load. Misc JS cleanup.