 
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
 
+        // Create user defaults and load correct default preferences
         let defaults = UserDefaults.standard
         
         // Load default preferences into user defaults, in case these preference keys have not been set by user yet
         let prefsFile = Bundle.main.url(forResource: "DefaultPreferences", withExtension: "plist")!
-        let prefsDict = NSDictionary(contentsOf: prefsFile)!
-        defaults.register(defaults: prefsDict as! [String: Any])
+        let prefsDict = NSDictionary(contentsOf: prefsFile) as! [String: Any]
+        defaults.register(defaults: prefsDict)
 
         // Set the UI Theme for the saved theme key
         if let theme = UITheme(rawValue: defaults.integer(forKey: userDefaultTheme)) {

        // Figure out whether we have onboarded the user or not
        let hasOnboarded = defaults.bool(forKey: userDefaultOnboardingComplete)

        if let terms = defaults.stringArray(forKey: userDefaultTerms) {
            // TODO: Remove this code whenever old user base is migrated to version 2.0
            // Code in here due to the new re-ordering of default terms and there locations in version 2.0.
            if terms.count == 4 && terms[0] == "Spring" && terms[1] == "Summer" && terms[2] == "Fall" && terms[3] == "Winter" {
                defaults.set(["Winter", "Fall", "Summer", "Spring"], forKey: userDefaultTerms)
            }
        }
        
        if !hasOnboarded { self.presentOnboarding() }
        
        // Perform any required migrations
        DatabaseManager.setupRealm() {
            // App has launched and migrations finished, increase sessions
            self.incrementSessions()

        if TARGET_OS_SIMULATOR != 0 || TARGET_IPHONE_SIMULATOR != 0 {
            print("Realm path: \(Realm.Configuration.defaultConfiguration.fileURL!)")
            // Catches all exceptions and prints
            NSSetUncaughtExceptionHandler { print($0) }
            // For UITesting, handle any launch options
            self.prepareForUITesting()
        }
        return true
    }
    
