         }
         
         let cells = tableView.visibleCells
-        if !cells.isEmpty {
-            for i in 0..<cells.count {
-                if alarmModel.alarms[i].enabled {
-                    (cells[i].accessoryView as! UISwitch).setOn(true, animated: false)
-                    cells[i].backgroundColor = UIColor.white
-                    cells[i].textLabel?.alpha = 1.0
-                    cells[i].detailTextLabel?.alpha = 1.0
-                }
-                else {
-                    (cells[i].accessoryView as! UISwitch).setOn(false, animated: false)
-                    cells[i].backgroundColor = UIColor.groupTableViewBackground
-                    cells[i].textLabel?.alpha = 0.5
-                    cells[i].detailTextLabel?.alpha = 0.5
-                }
-            }
+        for (index,cell) in cells.enumerated() {
+            let enabled = alarmModel.alarms[index].enabled
+            let alpha =  enabled ? 1.0 : 0.5
+            let color = enabled ? UIColor.white : UIColor.groupTableViewBackground
+            (cell.accessoryView as! UISwitch).setOn(enabled, animated: false)
+            configCell(cell: cell, bgColor: color, alpha: CGFloat(alpha))
         }
     }
     

    @IBAction func switchTapped(_ sender: UISwitch) {
        let index = sender.tag
        alarmModel.alarms[index].enabled = sender.isOn
        if sender.isOn {
            print("switch on")
            sender.superview?.backgroundColor = UIColor.white
            alarmScheduler.setNotificationWithDate(alarmModel.alarms[index].date, onWeekdaysForNotify: alarmModel.alarms[index].repeatWeekdays, snoozeEnabled: alarmModel.alarms[index].snoozeEnabled, onSnooze: false, soundName: alarmModel.alarms[index].mediaLabel, index: index)
            let cells = tableView.visibleCells
            if !cells.isEmpty {
                cells[index].textLabel?.alpha = 1.0
                cells[index].detailTextLabel?.alpha = 1.0
            }
        }
        else {
            print("switch off")
            sender.superview?.backgroundColor = UIColor.groupTableViewBackground
            let cells = tableView.visibleCells
            if !cells.isEmpty {
                cells[index].textLabel?.alpha = 0.5
                cells[index].detailTextLabel?.alpha = 0.5
            }
            alarmScheduler.reSchedule()
        }
    }

    
    // Override to support editing the table view.
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        alarmModel = Alarms()
        alarmScheduler.checkNotification()
        tableView.reloadData()
        //dynamically append the edit button
        if alarmModel.count != 0 {
