The smell of someone else's poop is definitely something we try to steer clear of — for obvious reasons. But it turns out, poop smells can provide valuable intel for certain animals. Mandrills, a type of monkey found only in rain forests in Africa, sniff dung to figure out if another mandrill has parasites; if the smell test is positive, the monkeys avoid contact with the infected members of their group, according to a new study. This type of behavior might seem really mean, but it can actually save lives.

Behavior, in fact, is incredibly important for keeping ourselves from getting sick. If you want to prevent illness, you can do things like installing a septic system in your house, refraining from kissing sick people, or, in the 19th century, not wandering into a TB ward for no reason. This is called “behavioral immune system” — a term that “refers to the suite of behavioral mechanisms that act as a first line of defense against parasites and pathogens,” the study’s lead researcher, Clémence Poirotte, writes in an email to The Verge, citing the famed biologist George Schaller.

A fascinating example of behavioral immune system can be found among mandrills, according to a study published today in Science Advances. These monkeys are very social: they live in very large groups called hordes that sometimes count as many as 800 animals. This type of communal living has benefits like protection, stimulation, co-grooming for nutritional and hygienic purposes, and some amount of resource pooling. But it also has risks: predominantly disease. So to avoid getting infected, mandrills seem to have evolved to avoid other mandrills that have parasites — based on the smell of their poop.

Parasites and other infectious diseases can change body odor — including poop odor! Mandrills will often examine each other’s butts closely, and then spend significantly less time near parasite-infested monkeys, the study says. For example, they’ll refrain from the common social behavior of grooming the sick mandrill, which might cause them to eat and get the parasites. “They do not simply ostracize parasitized individuals from the group, they avoid grooming them, particularly around the peri-anal area,” says Poirotte, who specializes in ecology at the Centre.

There are only two other known examples of this type of strategy in the wild: lobsters that don’t share dens with other lobsters when they have a lethal virus, and bullfrog tadpoles that won’t swim alongside parasite-infested tadpoles. For the most part, behavioral immunity has only been studied in the context of mating. (Does it affect the way an animal picks its partner?) Now, scientists want to understand if it also affects how highly social animals choose who to hang out with. Basically if nature is a high school, which clique is most likely to keep them alive?

Poirotte says the parasite-host partnership is still worthy of a lot of further study, since the two will constantly evolve to outsmart and outlast each other: “[Parasites] could for example modify host odor in a way that prevents detection of parasitized individuals from their conspecifics.” In this study, she and her team analyzed pathogens like E. coli, B. coli, and E. histolytica, but she says she’d like to expand her research on other parasites, too.

The group of mandrills described in the study live in a private park in southern Gabon. Unfortunately, the monkeys are pretty severely threatened by deforestation and hunting. The IUCN Red List officially designates them as a vulnerable species; their population has decreased by 30 percent over the last 30 years.