fixed closing curl instance too early; fixes error handling warnings