sslsockets and code refactorization. not tested!