In situ observation of magnesium deposition and the effect of preconditioning