Add SSL support. Refactor some methods.