         return SignalProducer{ observer,_ in
             switch thread{
             case .main:
-                let threadRealm:Realm
-                if let realm = realm{
-                    threadRealm = realm
-                }else{
-                    threadRealm = try! Realm()
-                }
+                let threadRealm = try! realm ?? Realm()
                 threadRealm.beginWrite()
                 threadRealm.add(self, update: update)
                 try! threadRealm.commitWrite()

            }
            switch thread{
            case .main:
                let threadRealm:Realm
                if let realm = realm{
                    threadRealm = realm
                }else{
                    threadRealm = try! Realm()
                }
                threadRealm.beginWrite()
                for object in self{
                    operation(object)

        return SignalProducer{ observer,_ in
            switch thread{
            case .main:
                let threadRealm = try! realm ?? Realm()
                if !update && objectAlreadyExists(realm: threadRealm, object: self){
                    observer.send(error: .alreadyExists)
                    return
