 
                 self.updateStatus("Uploading complete successfully.")
 
-                if(self.deleteFilesSwitch.on) {
-                    NSLog("Set of files to be kept: " + filesToBeKept.joinWithSeparator(", "))
-
-                    let remoteDirectoryListing = sftpSession!.contentsOfDirectoryAtPath(self.remoteDir.text!)
-                    var filesAlreadyRemote = Set<String>()
-                    for remoteFile in remoteDirectoryListing as! [NMSFTPFile] {
-                        if !remoteFile.isDirectory {
-                            filesAlreadyRemote.insert(remoteFile.filename)
-                        }
-                    }
-
-                    NSLog("Remote directory listing: " + filesAlreadyRemote.joinWithSeparator(", "))
-
-                    let filesToRemove = filesAlreadyRemote.subtract(filesToBeKept)
-
-                    NSLog("Files to remove: " + filesToRemove.joinWithSeparator(", "))
-
-                    for fileToRemove in filesToRemove {
-                        let fullFilePath = self.remoteDir.text! + "/" + fileToRemove
-                        self.updateStatus("Removing remote file " + fullFilePath)
-                        sftpSession!.removeFileAtPath(fullFilePath)
-                    }
+                if self.deleteFilesSwitch.on {
+                    self.deleteRemotePhotos(sftpSession!, filesToBeKept: filesToBeKept)
                 }
 
                 self.updateStatus("Disconnecting...")

    case NotAuthorized
}

class ViewController: UIViewController, UITextFieldDelegate {
    @IBOutlet weak var host: UITextField!
    @IBOutlet weak var port: UITextField!

        }
    }

    func deleteRemotePhotos(sftpSession: NMSFTP, filesToBeKept: Set<String>) {
        NSLog("Set of files to be kept: " + filesToBeKept.joinWithSeparator(", "))

        let remoteDirectoryListing = sftpSession.contentsOfDirectoryAtPath(self.remoteDir.text!)
        var filesAlreadyRemote = Set<String>()
        // swiftlint:disable:next force_cast
        for remoteFile in remoteDirectoryListing as! [NMSFTPFile] {
            if !remoteFile.isDirectory {
                filesAlreadyRemote.insert(remoteFile.filename)
            }
        }

        NSLog("Remote directory listing: " + filesAlreadyRemote.joinWithSeparator(", "))

        let filesToRemove = filesAlreadyRemote.subtract(filesToBeKept)

        NSLog("Files to remove: " + filesToRemove.joinWithSeparator(", "))

        for fileToRemove in filesToRemove {
            let fullFilePath = self.remoteDir.text! + "/" + fileToRemove
            self.updateStatus("Removing remote file " + fullFilePath)
            sftpSession.removeFileAtPath(fullFilePath)
        }
    }

    func updateStatus(status: String, count: Int = 0, total: Int = 0, percentage: Float = -1) {
        NSLog("Status change: " + status)

