             sshQueue.async {
                 session.disconnect()
             }
+        }else{
+            NMSSHLogger.shared().logError("Session is nil")
         }
     }
     

            sshQueue.async {
                channel.closeShell()
            }
        }
    }
}

            }
        }
    }
    
    //write bunch of commands
    //If session channel is exist, then the handler will return only errors with sending commands
    //an empty results array means that there was not any error writnig commands
    public func writeBunch(commands: [String], completionHandler: @escaping (_ error: PVPError?, _ results: [String]?) -> Void) {
        
        if let channel = channel {
            sshQueue.async {
                
                var answers: [String] = []
                
                for command in commands {
                    
                    //trying send command
                    do {
                        try channel.write(command)
                        
                    }catch let error {
                        
                        answers.append("Error: \(error.localizedDescription)")
                    }
                }
                
                self.mainQueue.async {
                    completionHandler(nil, answers)
                }
            }
        }else{
            completionHandler(PVPError.noSessionChannel, nil)
        }
    }
    
    //execute bunch of commands
    //If session channel is exist, then the handler will send an array of answers.
    //An empty string in the results array means that there is no error with this command
    public func executeBunch(commands: [String], completionHandler: @escaping (_ error: PVPError?, _ results: [String]?) -> Void) {
        
        if let channel = channel {
            sshQueue.async {
                
                var answers: [String] = []
                
                for command in commands {
                    
                    //trying send command
                    do {
                        let response = try channel.execute(command)
                        
                        answers.append(response)
                    }catch let error {
                        
                        answers.append("Error: \(error.localizedDescription)")
                    }
                }
                
                self.mainQueue.async {
                    completionHandler(nil, answers)
                }
            }
        }else{
            completionHandler(PVPError.noSessionChannel, nil)
        }
    }
}

//MARK: - Session public methods
extension PVPSSHManager {
    
    //connecting session and authorizing
    public func connectSessionAndAuthorize(completionHandler: @escaping (_ error: PVPError?) -> Void) {
        
        guard let pass = password else{
            
