SNI support, clean-up, bug fixes

This adds SNI-support, fixes #1, fixes #3 and fixes #4.