cURL: implement new functionality with cleanup and fixes