Switch to recreating an SCPreferencesRef each time instead of only once at startup
Fix type of oldStateChangeCount variables