Leaf-cutter ants are one of the world’s most organized species, sending out swarms of individuals to cut off leaf scraps and carry them back to the nest. Now, it seems, they’re even smarter than we thought: They can adjust on the fly.

To test the insects’ intelligence, a team of scientists led by Audrey Dussutour at the University of Sydney threw a road block in their way. The researchers built a lab setup in which the ants could only travel between a source of leaves and their nest via a short passageway with a roof only one centimeter off the ground. But instead of getting confused or frustrated that their cargo wouldn’t fit under the bridge, the ants adapted their tactics.

Before, a smaller number of ants had hauled the bigger pieces of leaf, but once the ants hit the low ceiling, they drew up a new game plan—many more ants who had not been carrying leaves started doing so, and everyone carried smaller pieces. That way, the ants managed to keep the same amount of foliage flowing into the nest, and all without any traffic jams or ant pileups.

But how did they learn so fast? Many ant species communicate by releasing pheromones or rubbing their appendages together to make sounds. Because the leaf-cutters immediately started cutting smaller pieces after they saw their colleagues struggling at the road block, Dussutour’s team speculates that the ants possess some kind of “template”—when they see other workers with big pieces of leaf getting stuck, they know what to do.