bail out when we get a self-signed certificate
restructuring and cleanups