China has long served as North Korea’s primary and most powerful ally, accounting for the vast majority of North Korea’s export market and serving as the commanding big brother who’s willing to stand toe to toe with the superpowers of the West in favor of Kim Jong-un’s reclusive state, but even China’s tolerance for Kim’s continued aggression seems to be waning. In order to understand why, we first need to understand why China was willing to support North Korea in the first place.

From the outside looking in, it can be difficult to wrap one’s head around why China, a global economic power that is feverishly expanding its military capability, would want to risk conflict with the United States. The United States is woefully unprepared for a military conflict with a “near-peer” like China, so it seems unlikely that either nation would revel in the opportunity to start shooting at each other. Moreover, China makes a lot of money in U.S. markets, and that money would dry up if relations between the two countries were to sour to the point of war.

The combination of the potential for a bloody and drawn-out conflict that would certainly involve many other nations and could potentially devolve into a third world war, combined with the financial repercussions of even winning a war against their biggest customer base, should be more than enough to convince China to play nice, one would think. So what benefit does siding with a despotic dictator ruling over a weak nation with a struggling economy possibly serve?

It really all boils down to one thing: stability.

China has long maintained a simple but effective policy regarding North Korea that lays out their three main priorities when it comes to managing relations between Kim Jong-un and the rest of the world: no war, no instability, no nukes.

These three tenets, listed in order of priority, were not established out of a sense of responsibility to the North Korean people or its leader, but rather as a means to ensure China does not end up responsible for a frantic population driven to leave a destabilized North Korea as the result of international or domestic conflict.

The first element of China’s North Korean policy—no war—speaks to their experience in the Korean War. Not only did China suffer a fair share of casualties, but they faced the real possibility of a unified, West-friendly Korea right in their neighborhood. The second—no instability—is based entirely on China not wanting hundreds of thousands of North Korean refugees to flee their homeland in search of safer homes in China. A collapse of the North Korean infrastructure would mean porous borders, refugees, and now, nuclear materials that could easily be lost or put up for sale on the black market.

Finally, the third tenet of China’s policy on North Korea is also the one they’ve deemed the least important: no nukes. For China, they would rather see a stable, nuclear-armed North Korea than an unstable or warring disarmed one. It’s just good policy for China to keep North Korea’s problems firmly planted within its own borders. If that means having to stand up for them from time to time, it seems worth it to keep bigger problems off of their plate.