For decades, automakers have been caught between building an engine that squeezes a lot of energy out of the fuel it burns and one that has low emissions. It’s not an easy tension to resolve. “Negotiating both fuel consumption and emissions is a hard tradeoff,” says Anna Stefanopolou, professor of mechanical engineering at the University of Michigan.

When engineers at Volkswagen allegedly inserted a few lines of code into the diesel cars’ electronic brains to circumvent emissions testing, they found a solution to this existential automotive conflict. Drivers got low emissions during the test, and high performance the rest of the time. The only problem: It’s way outside of the rules. The company might have gotten away with it, too, if it hadn't been for those pesky engineers—and the basic chemistry of the diesel engine.

According to the US EPA, those lines of code hid the fact that nearly half a million diesel VWs in the US spewed up to 40 times more nitrogen oxide from their tailpipes than testing indicated. Volkswagen has now confirmed that the problem actually affects approximately 11 million diesel cars worldwide. Diesel engines use a different mix of fuel than gasoline engines and don’t use spark plugs to induce combustion—relying instead on highly compressed, heated air and fuel injected as droplets. If a diesel engine doesn't get enough oxygen to combust the fuel, it'll emit all kinds of gunk—nitrogen oxides, uncombusted fuel, and particulate matter (soot, basically).

All that gunk is a big problem. Exposed to sunlight, nitrogen oxides convert to ozone—making smog. How much depends on a bunch of variables, like sunlight exposure and what happens to the hydrocarbon emissions (the uncombusted fuel), plus the temperature and local winds.

However much extra crap came from the VWs, it won’t be good. Exposure to nitrogen oxide and ozone is linked to increased asthma attacks, respiratory illnesses, and in some cases premature death. Ozone also worsens existing cardiovascular and lung disease.

To deal with those emissions, "you have a whole chemical factory at the tailpipe that traps the oxides," Stefanopolou says. This bumps the sticker price for diesel cars by $5,000 to $8,000 per vehicle. (On the other hand, diesels get better mileage, especially in highway driving.)

For years, diesel trucks and buses were the biggest polluters on the highway. But carmakers adapted a relatively new technology called selective catalytic reduction—the same tech that scrubs pollutants from factory smokestacks—to the tailpipe of the diesel engine.

Here's how it works: Inside a honeycombed chamber, the scrubbing system sprays a liquid made of 30 percent urea and 70 percent water into the diesel exhaust. This sets off a chemical reaction that converts nitrogen oxides into nitrogen, oxygen, water and small amounts of carbon dioxide—molecules that aren't as harmful to human health. Catalytic scrubbing was supposed to cut diesel NOx emissions up to 90 percent, according to the Diesel Technology Forum, an industry group based outside Washington. That made diesel engines clean enough to use in passenger cars, which have stricter emissions rules.

The scrubbing chemistry is also what gave away Volkswagen's alleged cover-up. In 2013, a small non-profit group decided to compare diesel emissions from European cars, which are notoriously high, with the US versions of the same vehicles. A team led by Drew Kodjak, executive director of the International Council on Clean Transportation, worked with emissions researchers at West Virginia University to test three four-cylinder 2.0-liter diesel cars in the Los Angeles area: a Jetta, a Passat, and a BMW. Only the BMW passed.

“We felt that it would be possible to get low emissions for diesels,” Kodjak said. “You can imagine our surprise when we found two of the three vehicles had significant emissions.”

The ICCT reported its findings to the EPA and the California Air Resources Board. Regulators met with VW officials in 2014 and the automaker agreed to fix the problem with a voluntary recall. But in July 2015, CARB did some follow up testing and again the cars failed—the scrubber technology was present, but off most of the time.

How this happened is pretty neat. Michigan’s Stefanopolou says computer sensors monitored the steering column. Under normal driving conditions, the column oscillates as the driver negotiates turns. But during emissions testing, the wheels of the car move, but the steering wheel doesn't. That seems to have have been the signal for the “defeat device” to turn the catalytic scrubber up to full power, allowing the car to pass the test.

Stefanopolou believes the emissions testing trick that VW used probably isn’t widespread in the automotive industry. Carmakers just don’t have many diesels on the road. And now that number may go down even more.