Refactored code to use prefs class