I was wondering if that was the problem. Would magnesium work then?

I thought this method was also used with pipelines, to reduce corrosion.