When your food/water/nutrition is more perfectly balanced and you still have probs you may try eletrolyte capsules. I found Hammer e-caps helped me a bunch. I cramped up bad on a 100km when all other variables were good (food,water, training) and one e-cap per hour two weeks later on a faster century I suffered not one cramp. Might have been chance but for $20 for 100 caps a chance I'll take. I take one per hour during hotter weather when I'm riding 2+ hours.