REFUGEES are reasonable people in desperate circumstances. Life for many of the 1m-odd asylum-seekers who have fled Syria, Iraq, Afghanistan and other war-torn countries for Europe in the past year has become intolerable. Europe is peaceful, rich and accessible. Most people would rather not abandon their homes and start again among strangers. But when the alternative is the threat of death from barrel-bombs and sabre-wielding fanatics, they make the only rational choice.

The flow of refugees would have been manageable if European Union countries had worked together, as Angela Merkel, Germany’s chancellor, has always wished (and The Economist urged). Instead Germany and Sweden have been left to cope alone. Today their willingness to do so is exhausted. Unless Europe soon restores order, political pressure will force Mrs Merkel to clamp down unilaterally, starting a wave of border closures (see article). More worrying, the migrant crisis is feeding xenophobia and political populism. The divisive forces of right-wing nationalism have already taken hold in parts of eastern Europe. If they spread westward into Germany, France and Italy then the EU could tear itself apart.

The situation today is a mess. Refugees have been free to sail across the Mediterranean, register and make for whichever country seems most welcoming. Many economic migrants with no claim to asylum have found a place in the queue by lying about where they came from. This free-for-all must be replaced by a system in which asylum applicants are screened when they first reach Europe’s borders—or better still, before they cross the Mediterranean. Those who are ineligible for asylum should be sent back without delay; those likely to qualify should be sent on to countries willing to accept them.

Order on the border

Creating a well-regulated system requires three steps. The first is to curb the “push factors” that encourage people to risk the crossing, by beefing up aid to refugees, particularly to the victims of the civil wars in Syria and Iraq, including the huge number who have fled to neighbouring countries such as Turkey, Jordan and Lebanon. The second is to review asylum claims while refugees are still in centres in the Middle East or in the “hotspots” (mainly in Greece and Italy), where they go when they first arrive in the EU. The third element is to insist that asylum-seekers stay put until their applications are processed, rather than jumping on a train to Germany.

All these steps are fraught with difficulty. Consider the “push factors” first. The prospect of ending Syria’s civil war is as remote as ever: peace talks in Geneva this week were suspended without progress. But the EU could do a lot more to help refugees and their host countries. Scandalously, aid for Syrians was cut in 2015 even as the war grew bloodier: aid agencies got a bit more than half of what they needed last year, according to the UN. Donors at a conference on Syria in London this week were asked for $9 billion for 2016—about as much as Germans spend on chocolate every year. Far more is needed and will be needed every year for several years.

Europe’s money should be used not only to feed and house refugees but also to coax host countries into letting them work. For the first four years of the conflict Syrians were denied work permits in Turkey, Jordan and Lebanon. Recently Turkey has begun to grant them. Donors should press Jordan and Lebanon to follow. European cash could help teach the 400,000 refugee children in Turkey who have no classes.

Sometimes the answer is no

The next task is to require asylum-seekers to register and be sorted as close to home as possible, probably Turkey, Lebanon and Jordan. Ideally those who travelled by boat to Europe would be sent back to a camp in one of those three countries—to prove that they had just wasted their precious savings paying people-traffickers to take them on a pointless journey. But that would meet legal and political objections, partly because of Turkey’s human-rights record (see our special report this week). So, there should also be processing camps in the first EU country they reach, probably Greece or Italy.

The cost of this should fall on the whole EU, since the aim is to establish control over its external borders. Dealmaking is possible. In exchange for hosting large refugee hotspots and camps on its soil, Greece should get help with its debt and budgets which it has long sought to ease its economic crisis.

INTERACTIVE: A guide to Europe’s migrant crisis, in numbers Refugees will fall in with this scheme (rather than cross the EU illegally) only if they are confident that genuine applications will be accepted within a reasonable time. So the EU needs to spend what it takes to sort through their claims swiftly. And member states ought to agree to accept substantial numbers of bona fide asylum claimants. Some refugees may prefer Germany to, say, France—and there is little to stop them crossing borders once they are inside the Schengen area. But, if they are properly looked after, most will stay put. The crisis needs a bigger resettlement programme than the one run by the UN’s refugee agency, which has only 160,000 spaces. Countries outside the EU, including the Gulf states, can play their part. Priority should go to refugees who apply for asylum while still in Turkey, Jordan or Lebanon—to reduce the incentive for refugees to board leaky boats to Greece. Ineligible migrants will have to be refused entry or deported. This will be legally difficult, and it is impossible to repatriate people to some countries, such as Syria. But if the system is not to be overwhelmed or seen as unfair and illegitimate by EU citizens, the sorting must be efficient and enforceable. EU governments should sign and implement readmission agreements allowing rejected migrants to be sent home quickly to, say, Morocco or Algeria. If such agreements are impossible (or if, as with Pakistan, governments fail to honour them), the prospect of waiting indefinitely in Greece will make economic migrants who want to reach Germany hesitate before coming. Once these measures are in place, it will become possible to take the most controversial step: halting the uncontrolled migrant flow across Greece’s northern border with Macedonia. It has become clear over the past five months that Europe cannot gain control over the numbers or the nature of the migrant stream while border officials wave asylum-seekers through and bid them safe travel to northern Europe.

Since the start of the refugee crisis, we have argued that Europe should welcome persecuted people and carefully manage their entry into European society. Our views have not changed. Countries have a moral and legal duty to provide sanctuary to those who flee grave danger. That approach is disruptive in the short term, but in the medium term, so long as they are allowed to work, refugees assimilate and more than pay for themselves. By contrast, the chaos of recent months shows what happens when politicians fail to take a pan-European approach to what is clearly a pan-European problem. The plan we outline would require a big chunk of cash and a lot of testy negotiations. But it is in every country’s interest to help—because all of them would be worse off if the EU lapses into a xenophobic free-for-all.

There is an encouraging precedent, too. When more than 1m “boat people” fled Vietnam after the communists took over in 1975, they went initially to refugee camps in Hong Kong and other parts of Asia before being sent to America, Europe, Australia and wherever else would take them. They arrived with nothing but adapted astonishingly fast: the median household income for Vietnamese-Americans, for example, is now above the national average. No one in America now frets that the boat people will not fit in.