         touchIDTableViewCell.accessoryView = touchIDSwitch
         setPGPKeyTableViewCellDetailText()
         setPasswordRepositoryTableViewCellDetailText()
-        setTouchIDSwitch()
-        setPasscodeLockRepositoryTableViewCellDetailText()
-    }
-    
-    private func setPasscodeLockRepositoryTableViewCellDetailText() {
+        setPasscodeLockTouchIDCells()
+    }
+    
+    private func setPasscodeLockTouchIDCells() {
         if PasscodeLockRepository().hasPasscode {
             self.passcodeTableViewCell.detailTextLabel?.text = "On"
+            Globals.passcodeConfiguration.isTouchIDAllowed = true
+            touchIDSwitch.isOn = Defaults[.isTouchIDOn]
         } else {
             self.passcodeTableViewCell.detailTextLabel?.text = "Off"
-            touchIDSwitch.isEnabled = false
             Globals.passcodeConfiguration.isTouchIDAllowed = false
+            Defaults[.isTouchIDOn] = false
+            touchIDSwitch.isOn = Defaults[.isTouchIDOn]
         }
     }
     

    func setPasscodeLock() {
        let passcodeSetViewController = PasscodeLockViewController(state: .set, configuration: Globals.passcodeConfiguration)
        passcodeSetViewController.successCallback = { _ in
            self.passcodeTableViewCell.detailTextLabel?.text = "On"
            self.touchIDSwitch.isEnabled = true
        }
        present(passcodeSetViewController, animated: true, completion: nil)
    }

    }
    
    func touchIDSwitchAction(uiSwitch: UISwitch) {
        if !Globals.passcodeConfiguration.isTouchIDAllowed {
            // switch off
            uiSwitch.isOn = Defaults[.isTouchIDOn]  // false
            Utils.alert(title: "Notice", message: "Please set the passcode lock first.", controller: self, completion: nil)
        } else {
            Defaults[.isTouchIDOn] = uiSwitch.isOn
        }
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
