Close to working function. Need to add the certificate