fixed memory leaks and improved stability. should work more or less but still only TLSv1 on broker side. #12