We’re used to thinking of dogs as our best friends. So it’s all the more upsetting—sometimes even personally offensive—when a beloved pet behaves badly.

Most of the time, unruly behavior can be fixed with dog training classes, a firm voice and a few well-timed treats. But what are owners supposed to do if their dogs act racist?

Perceived racism in dogs is a phenomenon acknowledged by many animal behaviorists—and common enough that there’s even a Key and Peele sketch about it. Many owners report that their normally friendly dogs will suddenly become stiff and growl at a random person: typically, someone with darker skin.

“I deal with that particular issue all of the time,” Suzi Schaefers of the Canine Psychology Center tells Quartz.

It’s an awkward, and potentially dangerous, situation for both dog owners and for the person on the receiving end. And there’s an ugly history behind dogs’ aggression: Writer Kelly Mays McDonald details how police and state forces have long deployed dogs as weapons against people of color in a 2015 article for The Awl.

The good news is that dogs aren’t actually racist. In most cases, dogs’ negative reactions can be chalked up to improper socialization.

In most cases, dogs’ negative reactions can be chalked up to improper socialization.

A lot of dog owners don’t go out of their way to expose puppies to people of all races, genders, sizes, and ages. If a dog is raised in a homogenous community with limited access to the world, they may be hesitant—and sometimes aggressive—in the presence of something or someone new. In other words, dogs’ behavior problems reflect the segregated ways in which many Americans still live.

Moreover, 45% of white households in the US own a dog, compared to 20% of black families, according to a 2010 survey by the Pew Research Center. So proportionately more dogs are socialized around people with lighter skin, and therefore have a stronger reaction to darker-skinned people.

Dogs may also respond to perceived discomfort in the people they meet. In a 2010 article in Newsweek, Raina Kelley explained how her own apprehension toward dogs could perpetuate a negative cycle:

Dogs’ behavior problems reflect the segregated ways in which many Americans still live.

“Think about this. Say you were me, raised with cats and a little skittish with dogs (because I used to think some were racist) and you approached every dog with anxiety. That’s going to put the dog on edge because they always notice that kind of thing and they bark or show their teeth. Which, of course, further convinces you to be afraid of dogs, and so the cycle continues. It’s crazy, right? But it makes a whole heck of a lot more sense than racist dogs.”

Whatever the explanation, there’s no excuse for owners to allow such behavior to continue. So how can dog owners take action?

The first step is to stop using the term “racist,” as dogs do not have the intellectual capacity to be bigoted in the same way humans do.

“Usually, when people note that their dogs are acting ‘racist,’ they mean that dogs react negatively to people from certain social categories,” says Dr. Laurie Santos, director of the Comparative Cognition Laboratory and the Canine Cognition Center at Yale University. “But the idea of ‘racism’ has a lot of social connotations that might go beyond merely reacting negatively to someone based on how they look.”

Instead, Santos recommends calling dogs “biased” or “prejudiced.” Moreover, she notes there have as yet been no peer-reviewed studies that would prove beyond a doubt that skin color can trigger negative behaviors in dogs.

The best way to rectify a dog’s biased behavior is to go about training as methodically as if you were teaching a dog to sit.

“My instinct is that when we see dogs’ behavior, we have the intuition that dogs might be reacting based on a person’s race or ethnicity,” Dr. Santos says. But “we really need to test that intuition scientifically and so far these studies haven’t yet been done.”

With that understanding in mind, the best way to rectify a dog’s biased behavior is to go about training as methodically as if you were teaching a dog to sit. Like humans, dogs understand their world through pattern recognition. They’re able to learn commands through repeated exposure to them, and via immediate positive reinforcement when they successfully carry out a desired behavior.

Essentially, any time a prejudiced pup reacts neutrally or positively to a person of color, dog owners should reward them. They’ll quickly learn that keeping quiet around strangers leads to treats, and quit acting out altogether—even when the treats stop coming.

If dog owners do find themselves in a charged situation, they should get the dogs out of there as quickly as possible. This will limit dogs’ chances to express their bad behavior, helping to break them out of the pattern.

Most importantly, the onus is always on the dog owner to prevent their pet from acting out. Dogs don’t always know how to interact in a world shared with others. It’s our job to teach them.