Factored some code in Preferences.