added support for ssl/tls and bug fixes