The agency that's caused so much misery and cruelty is to be restructured, but without proper resources its successor won't be able to avoid the same mistakes.

David Cameron talks to UKBA workers, who are not suspected of any misconduct, at Heathrow Airport. Photograph: Getty Images

If you want to understand the misery the UK Border Agency (UKBA) has created in its four troubled years, you don’t want to start with the really juicy stuff - the acts of unwarranted violence against people it’s attempted to boot out of the country, the detention of rape victims, the numerous alleged cases of those deported, only to be tortured. Ignore that for now.

No, the devil’s in the more mundane cases. Like that of Emily Deane, 29, who’s been told she’ll be sent back to her native Philippines before the end of the month, forcing her to decide whether to take her one-year-old daughter, Lucy, with her, or leave her child with her husband.

Deane married Brian, from Preston, in the United Arab Emirates. They returned to the UK in September, and had intended to remain for no more than six months, but Brian lost his sales job with the medical company that employed him in the UAE.

Due to bad legal advice, they’d applied for the wrong type of visa, so began applying for Deane to receive permanent residency to remain in the country. But now they were trapped in the proverbial Kafkaesque bureaucratic nightmare. Sceptical immigration officials began questioning whether the couple really had a baby together. On Monday, they were told their application had been rejected.

Brian told the Lancashire Evening Post: “My wife already has a visa to visit the UK which expires soon and I am told the main reason is because we have applied for a permanent visa from within the UK. I can only assume they have thrown all this other nonsense at us about the marriage not being valid and saying we "claim" to have a daughter to back themselves up. If they don’t believe I have a daughter, I’ll take her along to meet them – and take a dirty nappy with me.”

Craig Colville, 31, from Wales, married Crystal, from Vancouver, last year. Crystal applied to change her visa. That the UKBA rejected her was a shock - but more surprising was the reason: “Your spouse (Craig) does not hold settled status, is not a British Citizen and is not a person with refugee leave/humanitarian protection." Craig was born in St Asaph in Wales, works in Mold and has lived in Chester for just under a year.

The letter allowed the couple to appeal, but the Border Agency replied saying the appeal had been quashed because the Colvilles missed the deadline. In this new letter, there was a new deadline as the Agency had failed to take the weekends into account. Craig told the Denbighshire Free Press: "The Border Agency are still holding Crystal's passport, which means she can't return home to see her family. Her brother is quadraplegic and she hasn't seen him in two years."

I could keep going with these ludicrous, cruel little examples of families torn apart by bureaucratic incompetence, but I expect you’re getting the picture.

The UK Border Agency was, of course, a body born of chaos. As the Guardian recently pointed out, “The stunning thing is that some people still stuck in the backlog of 310,000 cases that sealed UKBA's death warrant are actually a direct legacy from that [late 1990s] breakdown in the system.” A botched computerisation saw its backlog of cases soar into the hundreds of thousands, while it struggled to deal with the move from a paper to a computer-based system.

In 2006 the Home Secretary Charles Clarke lost his job because his department had lost track of released foreign national prisoners. Something had to be done, and the result was the creation of the Border and Immigration Agency - and then in 2008, UKBA, following a merger with UK visas and customs staff.

The problem was that all this rejigging never solved the fundamental problems of creaking systems and an insurmountable backlog. The new body, now at arm’s length and less accountable to parliamentary scrutiny, was shambolic and, as Theresa May would this week conclude, “secretive and defensive”.

Nowhere was this clearer than in its use of outsourcing. In the great game of providing jobs for the boys, UKBA was in a league of its own. Like many government entities, it felt the safest option was to give contracts to giant corporations, regardless of expertise or know-how. So this month we learned that G4S, which has no previous experience of providing social housing, is struggling to provide housing for asylum seekers. One of the firm's subcontractors has already resigned because it is not up to the task, while two others have “expressed concerns” about being able to provide the requisite services.

But incompetence is one thing - cruelty quite another. The fact the new body was kept at arm’s length lead Theresa May to conclude it had created a "closed, secretive and defensive" culture. Staff from sub-contractor Reliance were transporting Roseline Akhalu when she ended up pissing all over herself because she wasn't allowed to use a toilet. Staff from Tascor - which superceded Reliance - allegedly beat Marius Betondi and broke his nose during a failed deportation attempt. That was one of thousands of distressing cases, the product of a system in chaos.

The failure to prosecute G4S staff over the death of Jimmy Mubenga has been described as “perverse” by the former Chief Inspector of Prisons. Just as it failed to protect victims of torture, so the system failed to protect victims of slavery. The right-wing Centre for Social Justice (CSJ) found a litany of flaws in UKBA's procedures and concluded that “too often the CSJ has been told that UKBA involvement in the . . . process acts as a major barrier to victims [of slavery] to make a referral.”

We have been told about the restructuring plans. But restructuring last time round only made the mess worse, because the root causes of the problem weren’t addressed.

As Andy Jennings of the PCS told BBC Breakfast this morning: “This has been a car crash in slow motion, there have been endemic failures for a number of years because there has not been enough staff to do the job. The line given by Theresa May ignores the fundamental issues.”

The work of Mark Sedwell, the permanent secretary at the Home Office, in trying to stop the car crash can only be applauded. But without proper resources, the misery, incompetence and cruelty will only continue.