     private func checkTargetDeviceIsSetupDone() {
         self.targetDevice.transceiver!.sendIsDeviceSetupDone { result, isSetupDone in
             self.log("targetDevice.sendIsDeviceSetupDone: \(result.description()), isSetupDone: \(isSetupDone as Optional)")
+            if (self.canceled) {
+                return
+            }
             if (result == .NONE) {
                 self.targetDevice.isSetupDone = isSetupDone
                 self.startFirmwareUpdate()

    private func scanNetworks(onComplete: @escaping () -> ()) {
        self.targetDevice.transceiver!.sendScanNetworks { result, networks in
            self.log("sendScanNetworks: \(result.description()), networksCount: \(networks?.count as Optional)\n\(networks as Optional)")
            if (result == .NONE) {
                self.targetDevice.networks = self.removeRepeatedNetworks(networks!)
                onComplete()

    private func stepEnsureTargetDeviceCanBeClaimed() {
        self.targetDevice.transceiver!.sendGetDeviceId { result, deviceId in
            self.log("targetDevice.didReceiveDeviceIdReply: \(result.description()), deviceId: \(deviceId as Optional)")
            if (self.canceled) {
                return
            }
            if (result == .NONE) {
                self.targetDevice.deviceId = deviceId!
                self.checkTargetDeviceIsClaimed()
