             self.datecomponentsfromstring(datestringlocalized: self.now).month ||
             self.datecomponentsfromstring(datestringlocalized: datesnapshotstring).year! <
             self.datecomponentsfromstring(datestringlocalized: self.now).year! {
-            if self.islastSelectedDayinMonth(date: self.datefromstring(datestringlocalized: datesnapshotstring)) == true {
-                if self.datecomponentsfromstring(datestringlocalized: datesnapshotstring).month == self.datecomponentsfromstring(datestringlocalized: self.now).month! - 1 {
-                    let tag = NSLocalizedString("Keep", comment: "plan")  + " " + day + ", " + month + " " + NSLocalizedString("previous month", comment: "plan")
-                    self.snapshotsloggdata?.snapshotslogs![index].setValue(tag, forKey: "period")
-                } else {
-                    let tag = NSLocalizedString("Keep", comment: "plan")  + " " + day + ", " + month + " " + NSLocalizedString("earlier months", comment: "plan")
-                    self.snapshotsloggdata?.snapshotslogs![index].setValue(tag, forKey: "period")
-                }
-                return false
-            } else {
-                let date = self.datefromstring(datestringlocalized: datesnapshotstring)
-                if date.ispreviosmonth() {
-                    let tag = NSLocalizedString("Delete", comment: "plan") + " " + day + ", " + month + " " + NSLocalizedString("previous month", comment: "plan")
-                    self.snapshotsloggdata?.snapshotslogs![index].setValue(tag, forKey: "period")
-                } else {
-                    let tag = NSLocalizedString("Delete", comment: "plan") + " " + day + ", " + month + " " + NSLocalizedString("earlier months", comment: "plan")
-                    self.snapshotsloggdata?.snapshotslogs![index].setValue(tag, forKey: "period")
-                }
-                return true
-            }
-        }
-        return false
-    }
-
-    // Keep snapshots all selected day every previous months
-    private func previousmonthskeepAllselecteddayofweek(index: Int) -> Bool {
-        let datesnapshotstring = (self.snapshotsloggdata!.snapshotslogs![index].value(forKey: "dateExecuted") as? String)!
-        let month = self.datefromstring(datestringlocalized: datesnapshotstring).monthNameShort()
-        let day = self.datefromstring(datestringlocalized: datesnapshotstring).dayNameShort()
-        if self.datecomponentsfromstring(datestringlocalized: datesnapshotstring).month !=
-            self.datecomponentsfromstring(datestringlocalized: self.now).month ||
-            self.datecomponentsfromstring(datestringlocalized: datesnapshotstring).year! <
-            self.datecomponentsfromstring(datestringlocalized: self.now).year! {
-            if self.isselectedDayinWeek(date: self.datefromstring(datestringlocalized: datesnapshotstring)) == true {
+            if check!(self.datefromstring(datestringlocalized: datesnapshotstring)) == true {
                 if self.datecomponentsfromstring(datestringlocalized: datesnapshotstring).month == self.datecomponentsfromstring(datestringlocalized: self.now).month! - 1 {
                     let tag = NSLocalizedString("Keep", comment: "plan")  + " " + day + ", " + month + " " + NSLocalizedString("previous month", comment: "plan")
                     self.snapshotsloggdata?.snapshotslogs![index].setValue(tag, forKey: "period")

            } else if self.currentdaymonth(index: index) {
                self.snapshotsloggdata?.snapshotslogs![index].setValue(1, forKey: "selectCellID")
            } else {
                if self.keepallselcteddayofweek == true {
                    if self.previousmonthskeepAllselecteddayofweek(index: index) {
                        self.snapshotsloggdata?.snapshotslogs![index].setValue(1, forKey: "selectCellID")
                    }
                } else {
                    if self.previousmonthskeepLastselecteddayofweek(index: index) {
                        self.snapshotsloggdata?.snapshotslogs![index].setValue(1, forKey: "selectCellID")
                    }
                }
            }
        }

        return false
    }

    typealias Keepallorlastdayinweekfunc = (Date) -> Bool

    func keepallorlastdayinweek(index: Int) -> Bool {
        var check: Keepallorlastdayinweekfunc?
        if self.keepallselcteddayofweek {
             check = self.isselectedDayinWeek
        } else {
            check = self.islastSelectedDayinMonth
        }
        let datesnapshotstring = (self.snapshotsloggdata!.snapshotslogs![index].value(forKey: "dateExecuted") as? String)!
        let month = self.datefromstring(datestringlocalized: datesnapshotstring).monthNameShort()
        let day = self.datefromstring(datestringlocalized: datesnapshotstring).dayNameShort()
