Refactor on_settings_changed function