NAURAS NERAPI lived a comfortable life in Aleppo as a manager at a French catering company. Then came the Syrian war. He fled through Turkey and the Balkans to Germany, arriving in September 2015. “They put me on a bus but I didn’t know where I was going,” he explains. At a reception camp in Berlin he offered to help with the cooking. Today he speaks good German, lives in a shared flat and works as a chef. “In Aleppo I was left with nothing. Germany has been really good to me.”

His arrival coincided with a pivotal point in Angela Merkel’s career. As thousands made their way north and west, the chancellor declared “We can manage this,” and kept Germany’s borders open. Some 900,000 people arrived that year. Many predicted social chaos and Mrs Merkel’s downfall. Her apparent cruise to victory at the election on September 24th is a testament to two factors. First, thanks largely to a repatriation deal with Turkey, the numbers coming fell to 200,000 last year and just 80,000 so far this year. Second, and more happily, despite the strains most of the refugees are on the path to integration.

That path begins at the reception camps, from where newcomers are allocated to hostels like Rudower 18, in eastern Berlin. “We had three days to turn a derelict school into a home,” says Andrea Koppelmann, its director. Today, children’s paintings on the walls make it cheerier, but conditions remain basic: two or three families to a classroom. Women with babies peer nervously from behind bedsheets strung up for privacy. Other hostels focus on gay and lesbian refugees, lone men or unaccompanied minors. Friedrich Kiesinger, a psychologist whose charity, Albatros, cared for some 40,000 people in reception centres, took over an empty hotel and turned it into a home for tortured, traumatised and disabled refugees.

Within three months refugees with good prospects of staying should move into “community homes” with private bedrooms and kitchens. But building these takes time. One family has been in Rudower 18 for over two years. The final step—moving to a private flat—might take four or five years, says Mr Kiesinger. And in any case, he adds, integration does not end at that point: “We don’t want little Afghanistans growing up behind doors.” Education and work are both essential.

The first is going well. Children are usually attending school within three weeks of arrival, says Ms Koppelmann. Several teenagers at Rudower 18 attend the nearby Anne Frank School, where Dagmar Breske, a teacher, has devised a three-stage programme. In a class for illiterates, three Afghan boys haltingly read out lists of words beginning with the letter “A”. In another, the second stage, seven teenagers—mostly Syrians and Iraqis—are practising multiplication. A third class, the highest, is going over verb forms in preparation for the test determining whether they can enter regular German schools. Much of the work is cultural: training the teenagers to attend classes on time, follow rules and treat women with respect.

Getting adults into work is harder. Only those granted asylum can take jobs. Once they have submitted their applications, those with good prospects (like many Syrians) take a compulsory integration course: 600 hours of German lessons and 100 hours of civics. Many refugees have had little education (see chart 1) and progress towards work could take time (see chart 2). Mr Kiesinger blames the obsession with formal language qualifications: “The best way to learn German is to get a job.”

The asylum process is slow, with appeals taking years to process. Many officials are new and inexperienced. Schools and homes are often left without guidance. Yet everywhere people are muddling through and mucking in. Networks of schools, refugee homes and lawyers are springing up to share good practice. Legions of volunteers have turned out (100 at Mr Kiesinger’s hotel). Michele Pirger is one. “I just read up on the subject and decided to get involved,” she says. Having started by taking refugees to concerts, she now helps Copts who have fled persecution in Egypt, and houses one in her flat.

How well are the refugees integrating? The picture is varied. But those with previous education, a good prospect of asylum and an affinity with Germany—like Mr Nerapi—do best. And two big trends stand out. Men, who make up two-thirds of asylum applicants, struggle disproportionately. Many travelled to Germany alone, are disappointed by the drudgery they find and miss the social status they once enjoyed. Waiting while asylum or deportation processes drag on, they can easily slip into addiction, crime or radicalisation, says Mr Kiesinger. They need work: “It’s not just about money. It’s about friends and emotional stability…the young men who come here are too inactive.”

Children, on the other hand, integrate easily. In Ms Breske’s classrooms pupils who arrived months ago are fluent, self-confident and ambitious. Asked what they want to be, the boys tend to say policemen or engineers and the girls—many without headscarves—say doctors or lawyers. Omar, a 16-year-old from Baghdad, is about to start training as a hairdresser. Mahdiya, an Afghan, says she plans to study political science and become a politician: she admires Mrs Merkel. Ms Breske tells of a recent day-trip when German and refugee pupils mixed so well that “I could no longer tell them apart.”

Of course it will be many years before Germany can fully assess how well it has integrated its newcomers. But it is already clear that the gloomiest predictions were wrong. Germany has taken in more than 1.2m people over the past two years, and coped. There is much more to do. But for now, it seems to be managing.