Clean up curl code to match upstream