ISIS cannot challenge the Iraqi military for control over the country — and as such, it has slowly been losing territory in Iraq. But the Iraqi military is also weak and dependent on support from Shia militias and Kurdish peshmerga, so its progress has been slower than one might hope.

The Iraqi government and its allies outnumber ISIS by a fair margin. Over the course of the conflict, Iraqi forces have adapted to ISIS’s rapid offensive tactics, denying the group the element of surprise and allowing the Iraqis to start retaking ISIS territory. US airstrikes have also seriously hampered ISIS’s ability to mass troops, a critical part of its early strategy.

These factors have combined to put ISIS in a bad place in Iraq. “The Islamic State has been on the defensive in Iraq for more than eight months and it has lost practically every battle it has fought,” Iraq experts wrote in April 30, 2015 piece published in the Sentinel, the journal of the Combating Terrorism Center at West Point. Perhaps the most notable of these defeats was in Tikrit, a largely Sunni city and Saddam Hussein’s hometown. Iraqi forces retook the city in April.

But the Iraqi army is also a total mess, which explains why ISIS managed its dramatic initial successes despite always being seriously outnumbered. It also explains why ISIS has been able to counterattack very effectively in some places — as in Ramadi, which it took in May.

Take ISIS’s initial victory in Mosul: 30,000 Iraqi troops ran from 800 ISIS fighters. Those were 40-to-1 odds. Yet Iraqi troops ran because they were poorly deployed and didn’t want to fight and die for this government. There had been hundreds of desertions per month for months prior to the events of June 10, 2014. The escalation with ISIS is, of course, making it worse: At the time of ISIS’s first major offensive, the Iraqi army’s strength was estimated at 250,000 troops. In early 2015, that number was down to about 48,000.

The Iraqi army’s shrinkage has forced the army to depend on Shia militias, sometimes called popular mobilization units or special groups, in its war with ISIS. The roughly 70,000 to 120,000 militiamen have played a huge role in the Iraqi army’s push from the Shia-dominated south of the country into ISIS’s mostly Sunni northern holdings. The sectarian nature of these militias, as well as reports of abuse, have raised serious questions about whether the Iraqi army’s reliance on militia forces may end up undermining the country’s fragile reconciliation.

Kurdish peshmerga in Iraq’s north have also played an important role in the fighting, taking important targets like the Mosul Dam and the town of Sinjar, which sits on a key ISIS supply line from Syria.