You might be relatively Magnesium deficient.....Your magnesium requirement might be a lot higher than you think is needed. It might be worth taking a lot more Magnesium. 400mg is fairly low IMO. Something which might be worth trying is ascorbic acid powder mixed with Magnesium carbonate which forms Magnesium Ascorbate. Magnesium carbonate is a bright white powder when appears cloudy when added to water. Adding Ascorbic acid powder causes a fix acid/base reaction and when the quantities are correct it turns clear. Some warm water helps speed the reaction and so does a little stirring.
The result is a ph balanced source of vitamin c and magnesium which is highly absorbable. Another benefit is that mag carb food grade is fairly inexpensive and can be mixed with many different acids to form different magnesium salts.
Leg cramps are often caused by a mineral deficiency so it is worth trying to work out what that mineral deficiency is. Potassium, calcium, magnesium and/or sodium can be the cause so it might be worth experimenting with those to work out what the deficiency is.