Refactor of the ssh modifications

Cleaned the codded, added comments, and improved the readability.