Fixed curl global init and cleanup. Added debug lines