ssl and more refactoring