refactoring due to possible libssh2 threading issue.