A few hours after North Korean leader Kim Jong Un announced he had ordered his country's military on standby for nuclear strikes, the threats came up at Thursday's Republican presidential debate, and the candidates repeated one of the most common misconceptions about the hermit kingdom.

"You indeed do have a lunatic in North Korea," Sen. Marco Rubio said. Sen. Ted Cruz also called Kim a "lunatic," as did debate moderator Chris Wallace.

The image you get of Kim Jong Un is of an unpredictable wild man, an out of control crazy person, careening around northeast Asia with nuclear weapons. And I don't mean to pick on Rubio or Cruz; this is a widespread and bipartisan view.

But, in fact, while Kim is indeed a dangerous dictator who poses a real threat and oversees some of the world's worst human rights abuses, and seems to be personally quite eccentric, there is every reason to believe that, far from an erratic "lunatic," he is crude and brutal but quite rational dictator. And his behavior, especially including threats like Thursday's, starts to make a lot more sense when you understand how his regime really works.

There are, broadly speaking, three main reasons for North Korea's perennial threat-making — and why he never seems to actually follow through. In any given provocation, the motivation is usually some combination of these three; the degree to which one or another is more important varies, but ultimately these three make the country's behavior what it is.

1) It's about maintaining the big lie that keeps North Korea running

An awful lot of North Korea's behavior can be traced back to a problem it faced in the early 1990s, and how then-leader Kim Jong Il solved it.

The problem was this: For decades, the small and isolated country had been propped up by the Soviet Union as a bulwark against Western, capitalist influence in northeast Asia. When the Soviet Union collapsed, the subsidies went away, and North Korea sank into an economic catastrophe so terrible that as much as one-tenth of the population starved to death.

During this 1990s crisis, it looked to much of the world like North Korea was about to collapse, and not just because the society itself was crumbling. Its official state ideology had told North Koreans they lived in the freest and most prosperous society on Earth, and it placed North Koreans under a near-total information cordon to make this lie seem more believable.

The famine undermined that lie in two ways. First, no amount of propaganda could convince North Koreans, who were living off tree bark and grass, that their society was prosperous. And second, North Korea had no choice but to ease its border with China, allowing food to enter through the black market, even though this meant a number of North Koreans would glimpse the outside world, either by visiting neighboring northeastern China or through the foreign books and videos that were inevitably smuggled in.

The Soviet Union's collapse presented North Korea with another existential problem: It no longer had a superpower patron to protect it. Sure, China had an interest in keeping the Korean peninsula divided, but by the 1990s it had little love for North Korea, and would only do so much to protect it from a Western-dominated world that was openly hostile to the Kim regime.

Kim Jong Il's solution was something called the Songun or "military first" policy. This policy tells North Koreans that the reason they are hungry and impoverished and locked in a police state is because this is all necessary to fund the military and protect the country from enemies internal and external, so as to keep them safe from the imperialist Americans who are always just on the verge of invading — and, if able, would surely overwhelm them and do unspeakable things.

The Songun policy rallies North Koreans behind the regime not despite but because of their poverty, which is said to be a necessary function of the never-ending war against the imperialist American dogs. But keeping this lie alive requires the occasional provocation, just enough to make it look like North Koreans are indeed in a state of quasi-war, and also that the North Korean leaders are bravely and boldly lashing out against their enemies.

In that sense, it's all a show for the North Korean people, meant to maintain the big lie that keeps the country running — a terrifying, never-ending, low-boil war with the evil Americans and other enemies.

These provocations, since the mid-1990s when Songun began, have often been conducted in some form of nuclear weapons work, and Kim Jong Il's son, now-leader Kim Jong Un, has carried on this tradition. It's far from the only reason the country works with nuclear weapons, but it's an important one for understanding the threats.

2) It's about countering enemies that Kim knows are more powerful

The immediate context is helpful here: This week, the United Nations Security Council passed some of the toughest North Korea sanctions in years. Even China supported the sanctions, which it had helped to draft, and which punish North Korea's nuclear test from this January and a missile test from February.

When punished like this, North Korea often responds with provocations much like Thursday's nuclear threat.

It's not that Kim Jong Un actually desires a war with his enemies. His military, he knows, is antiquated and inferior and would certainly lose. Rather, what he likely wants to do, at least in part, is to raise tensions in the region — knowing that the US and North Korea's neighbors will then look to ratchet them down.

At the risk of insulting Kim Jong Un, it helps to think of North Korea's provocations as somewhat akin to a child throwing a temper tantrum. He might do lots of shouting, make some over-the-top declarations ("I'm never going back to school again") and even throw a punch or two. Still, you give the child the attention he craves and maybe even a toy, not because you think the threats are real or because he deserves it, but because you want the tantrum to stop.

The big problem here is not that North Korea will intentionally start a nuclear war, but rather that its threats, however empty, significantly raise the risk of unwanted conflict. It's disruptive and dangerous.

When North Korea fired six missiles into the sea this week, for example, no one thought South Korea was at danger of annihilation. But it does carry some real risks to have missiles crashing off your coast. Kim knows that his neighbors are more sensitive to this danger and disruption than he is.

It falls to North Korea's neighbors and to the US, then, to keep the Korean peninsula from spiraling out of control. Even if they don't ultimately offer Kim concessions to calm him down, as they have in the past, they've still got an interest in preventing future outbursts. Like parents straining to manage a child's tantrum, it's a power dynamic that oddly favors the weak and misbehaving.

3) Provocations play well in North Korean internal politics

Imagine being in your late 20s and suddenly taking control of a small country, one whose government is dominated by a small and ruthless coterie of more experienced military and party officials. Probably one of your biggest concerns would be making sure that those officials took you seriously — that they followed your orders and didn't remove you outright.

This has been Kim Jong Un's challenge since taking over from his father in early 2012: how to consolidate power among the country's governing elites. And he seems to have gone about this in two ways.

First, he has launched one of North Korea's most violent political purges in decades, exiling or executing a number of high-level officials, most infamously carving some up with anti-aircraft gun fire. (This has been apparently confirmed with satellite imagery, unlike the almost certainly false story of Kim feeding his uncle to wild dogs.)

And, second, Kim has conducted a steady series of military provocations: nuclear development, weapons tests, and a series of threats, in early 2013, to start World War III. A common theory among North Korea analysts is that this allows Kim to prove to military officials that he's a capable leader, and also that it rallies officials and citizens alike around him.

It seems unlikely that internal politics are the primary motivator in this case, though they're important for understanding Kim Jong Un's tendency for big provocations. Given that the nuclear threat came in response to UN Security Council sanctions, it's probably aimed mostly in response to that, both as a message to North Korea's enemies and to reassure its citizenry.