Added more handling for null references. Cleaned up the SSL socket connection.