         return false
     }
 
-    // Keep snapshots last selected day every previous months
-    private func previousmonthskeepLastselecteddayofweek(index: Int) -> Bool {
+    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()

            } 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")
                    }
                }
            }
        }

            self.datecomponentsfromstring(datestringlocalized: self.now).month ||
            self.datecomponentsfromstring(datestringlocalized: datesnapshotstring).year! <
            self.datecomponentsfromstring(datestringlocalized: self.now).year! {
            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")
