     var minutes:Int { return Int(alertTimeInMinutesTextField.stringValue) ?? 3 }
     
     var vEvents = Variable<[EKEvent]>([])
-    var crEvents:Results<CREvent>! = nil
+    lazy var crEvents:Results<CREvent> = try! Realm().objects(CREvent.self)
     
     var initTimer:Timer? = nil
-    var rxTimer:Timer? = nil
+    var dispatchWorkItem:DispatchWorkItem? = nil
     
     private func createNewReminder(event:EKEvent) -> EKReminder? {
         switch noAlertTimeCheckButton.state {

        vEvents.asObservable()
            .skip(1)
            .subscribe(onNext: { [unowned self] events in
                self.rxTimer?.invalidate()
                let userInfo = events
                self.rxTimer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(self.eventChanged(timer:)), userInfo: userInfo, repeats: false)
            })
            .disposed(by: disposeBag)
    }
        
    @objc private func eventChanged(timer:Timer) {
        defer { self.setupRxNotification() }
        // MARK: - keep data in Realm is updated
        let events = timer.userInfo as! [EKEvent]
        let realm = try! Realm()
        for crEvent in self.crEvents {
            let event = self.store.event(withIdentifier: crEvent.calendarItemIdentifier)
            let reminder = self.store.calendarItem(withIdentifier: crEvent.reminder!.calendarItemIdentifier) as? EKReminder
            

        
        if startButton.isEnabled == false { vEvents.value = eventQuery() }
    }
    
    private func dailyCleanUp() {
        let realm = crEvents.realm!
        let now = Date()
        
        realm.beginWrite()
        for crEvent in crEvents {
            if let event = store.event(withIdentifier: crEvent.calendarItemIdentifier),
                event.endDate > now
            {
                realm.delete(crEvent.reminder!)
                realm.delete(crEvent)
            }
        }
        try! realm.commitWrite()
    }
}
