fixed ssl error and cleaned up some code