refactor and sort prefs