fixing bug related to Mg2+ calculations