Refactoring ext/curl (only compilable now)