ssl support and client refactoring