Preferences stuff refactored