The chemistry and electrochemistry of magnesium production