Refactor saving settings and add test