refactor preferences.py