Refactored version with SSH support