     }
     
     override func peripheralDidDisconnect() {
-        // The aborted state should be checked first
-        if aborted {
-            // The device has reseted. Notify user
+        guard !aborted else {
+            // The device has resetted. Notify user
             logger.w("Upload aborted")
             delegate?.peripheralDidDisconnectAfterAborting()
-        } else if shouldReconnect {
+            return
+        }
+        
+        if shouldReconnect {
             shouldReconnect = false
             // We need to reconnect to the device
             connect()

        peripheral = nil
        cleanUp()
        
        if aborted {
            resetDevice()
            return
        }

        let name = peripheral.name ?? "Unknown device"
        logger.i("Connected to \(name)")
        
        guard !aborted else {
            resetDevice()
            return
        }
        
        discoverServices()
    }
    
    func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
