             log("due count hasn't changed: \(newCount)")
             completionHandler(.noData)
         }
-    } else {
-        log("response model is not GetStatusModel")
-        completionHandler(.failed)
+    }
+    
+    func processFetch(response: Response, oldCount: Int, completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
+        if let model = response.model as? GetStatusModel {
+            let newCount = model.expiredCards
+            resolveStatus(oldCount: oldCount, newCount: newCount, completionHandler: completionHandler)
+        } else {
+            log("response model is not GetStatusModel")
+            completionHandler(.failed)
+        }
     }
 }
 
+

        
        engine.statusAction.events.take(first: 1).react { event in
            if let response = event.value {
                processFetch(response: response, oldCount: oldCount, completionHandler: completionHandler)
            } else {
                log("didn't get a response: session may have expired")
                
                // give it time to see if the fetch attempt has triggered auto reauthentication
                let delayInSeconds = 10.0
                DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + delayInSeconds) { [weak self] in
                    // one more try
                    guard let engine = self?.appController?.srsViewController.engine else {
                        log("BkgFetch: not a fetch scenario, desisting")
                        completionHandler(.noData)
                        return
                    }
                    log("BkgFetch: fetching again")
                    engine.statusAction.events.take(first: 1).react { event in
                        if let response = event.value {
                            processFetch(response: response, oldCount: oldCount, completionHandler: completionHandler)
                        } else {
                            log("didn't get a response: failing")
                            completionHandler(.failed)
                        }
                    }
                    engine.refreshStatus()
                }
            }
        }
        engine.refreshStatus()
    }
}

func processFetch(response: Response, oldCount: Int, completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    if let model = response.model as? GetStatusModel {
        let newCount = model.expiredCards
        
        if newCount != oldCount {
            log("due count has changed: \(oldCount) -> \(newCount)")
            completionHandler(.newData)

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    // MARK: - Background fetch

    func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        
