                     self?.startObservingMass()
                     if self?.authorizationStatus == .authorized,
                         let observer = self?.appOpenObserver {
-                        NotificationCenter.default.removeObserver(observer)
+                        DispatchQueue.main.async {
+                            NotificationCenter.default.removeObserver(observer)
+                        }
                     }
             }
         #endif


        healthStore.deleteObjects(of: massType,
                                  predicate: predicate) { (success, deleted, error) in
                                    if deleted == 0 {
                                        completion(Error.unableToDelete)
                                    } else {
                                        completion(error)
                                    }
        }
    }


                                      metadata: metadata)
        
        healthStore.save(sample) { (success, error) in
            DispatchQueue.main.async {
                completion(error)
            }
        }
    }

