fixed tls bug

taken from pull request #20