Remove unnecessary block around if and made ssh connection creation synchronized