ssl fixed, cleaned up code