Not all runners get it, but for those who do have to deal with gastrointestinal issues before, during, or after a run, the experience can be a completely miserable one. Repeated GI distress can even cause some runners to back off their goals or quit the sport altogether. Before jumping into how to prevent this frustrating condition, it’s important to understand why GI distress (sometimes referred to as “runner’s trots”) is an issue with runners in the first place.

Greg McMillan, founder and head coach of McMillan Running, says GI issues arise in runners due to three factors. First, when we run, the blood that is normally going to our gut to process food is diverted to other working muscles in the legs and arms in order to optimize performance. “This is a positive for those muscles, but a negative for your stomach,” he says. The second factor is dehydration. And the third is the nature of the stomach itself. “Your gut is an acidic environment, and when you are exercising strenuously, you’re dehydrated, and blood is shunted away from the stomach to other muscles. You will have symptoms like acid reflux or have it on the other end with unhappy intestines that lead to diarrhea,” he says. This issue can manifest itself during times of high intensity/high stress work, like during track repeats or in a race, or it can surface during times of longer duration workouts, like 20-mile training runs for marathoners.

If you’re one of the unlucky victims of GI distress, these five preventative tips will help.

1. Avoid acidic foods and drinks.

In the day leading up to either a workout or a long run, be mindful of what you are putting into your gut. Common acidic foods that runners should avoid or minimize consumption of are eggs, milk, glutinous grains (i.e. white bread), tomatoes and nuts. Acidic drinks to avoid include coffee and alcohol. Some good non-acidic foods to consume are bananas, spinach and kale.

2. Start your run or workout hydrated and stay hydrated throughout.

Because a “dry” stomach is an upset one, it’s imperative that you monitor your fluid intake the day before a big run or race. When going for a long run, ensure you either carry fluids with you, or stash water and energy drinks along your route.

3. Avoid concentrated sugars later in a long run or workout.

According to McMillan, sugars can cause GI distress. “Sugar-reduction a double-edged sword,” he says. “Because the body needs the sugars to perform, but the GU that a runner takes at mile 5 of the marathon is not the same GU at mile 20 to the body,” he says. When a stomach gets a concentrated amount of sugars when it has reduced blood and is dehydrated, it rebels. As such, runners should dilute the energy drink or sports gel they consume so that its more gut-friendly. For marathoners, this is an essential element of training. If you’re concerned about diluting your energy, then you can try more advanced fueling options like Generation UCAN that are slower-acting than traditional energy sources.

4. Take an over-the-counter antacid before your run.

As with anything related to running, don’t introduce a new stimulus before a key workout or race. Instead, choose an easier training day to see how your body reacts to something like a Tums. An antacid will create a healthier environment in the gut. McMillan says that antacids are really benign, so the risk of an adverse reaction in the gut is low.

5. Monitor your overall diet.

Keep a log of what you consume and when—both solid and liquids–to see how your body responds. It’s common sense, but be sure that you don’t eat a large or fiber-filled meal right before a long run, race or workout. “Watch out for those spicy and high-acidic foods,” McMillian says. “Look up some non-acid food choices and experiment with them to see how your body responds,” he says. If you’ve been prescribed antibiotics recently, then consider taking care of your gut by ingesting probiotics such as yogurt, fermented foods or over-the-counter pills to ward off issues in advance.

Admittedly, there may be nothing that can prevent this frustrating and uncomfortable condition, but applying these five techniques will at least respect the gut and set the right environment to mitigate the stresses that come with intense exercise.

A final tip: you may find yourself in the middle of a workout or race having GI distress and become urgently faced with the difficult decision of either trying to hold it in or finding a Porta-John. While neither option is optimal, your best bet is most likely to go to the bathroom. “Just taking a quick stop and relieving yourself as much as possible is the way to go,” says Runners Connect coach Sarah Crouch.