SNI support, clean-up, bug fixes

This fixes #1, fixes #3 and fixes #4 and closes #5, closes #6 and closes #7.