Preferences crash fix

Two checks for null pointers before using them, to fix crashes that had occurred on editing preferences or loading preferecnes on startup.