Fixed function to save settings