Clean up CURL duplicate code