Added check in case of nil for preferences