extract curl handling to separate function