Move CURL calls to function