New York City was struck Wednesday morning by a tragic building explosion in Harlem that has, at latest count, killed at least seven people and injured 60 more. Being a New York City resident, my first thought, selfish as it may be, was, “How do I prevent something like that from happening to my building?”

As it turns out, there is something we could do to prevent more disasters like this from occurring, and it would also be good for lowering greenhouse gas emissions.

The cause of the explosion was a natural gas leak. Just a day earlier, as Capital New York notes, the Center for an Urban Future (CUF), a New York City-focused think tank, issued a report on New York’s decaying infrastructure. Among the problems it identified: leaky pipes carrying natural gas.

The city’s 6,300 miles of gas mains are an average of 56 years old. “Over half its gas mains were installed before 1960 and are made of unprotected cast iron, a corrosion-prone material,” CUF notes. Natural gas provides roughly two-thirds of New York City’s heating, and also is used for electricity generation. Gas is supplied to buildings by two utilities, depending on the part of the city: Con Edison, which in 2012 had 83 leaks for every 100 miles of main, and National Grid, which had 45 leaks per 100 main miles.

The pipes splitting off to individual buildings, called service lines, leak too. But leakage can be reduced significantly if pipes are replaced with better, newer materials, as CUF explains:

Prior to being bought out by National Grid, Brooklyn Union Gas Co. undertook an aggressive replacement program, eliminating leak-prone components and improving the integrity of the distribution system. Today, only 7 percent of National Grid’s service lines were installed prior to 1960 and only 5 percent are made of unprotected steel and cast iron. The respective figures for Con Edison are 22 percent and 24 percent.

National Grid now has roughly one-fifth as many leaks in its service lines as Con Ed, showing that investment in new lines makes a real difference.

And of course the leaks mean gas companies are losing significant amounts of gas, which is also lost money. According to CUF, “In New York City, 1.5 percent of National Grid’s gas is unaccounted for and 2.2 percent of gas entering Con Ed’s mains and service pipes—only the final stage in the extraction-transmission-distribution process—did not reach a final customer in 2012.”

There are two major consequences: a health and safety risk, as methane (the main component of natural gas) is highly flammable, and a lot of unnecessary greenhouse gas emissions. While burning natural gas releases less carbon dioxide than burning other fossil fuels, unburned methane released directly into the atmosphere is between 20 and 85 times as powerful a greenhouse gas as CO2, depending on the time frame you consider.

Scientists increasingly are finding that methane leakage throughout the natural-gas system is eliminating the potential climate advantage of natural gas. A study in Science last month found that the EPA underestimates greenhouse gas emissions from natural gas by 25 to 75 percent because the agency hasn’t accounted for leaks. If pipelines are upgraded using the best existing technology and leaks are minimized, natural gas could be much more climate-friendly.

Environmental advocates and CUF both recommend investing in pipeline system improvements to provide jobs, protect the public, and reduce greenhouse gas emissions. A national pipeline-fixing program would create way more jobs than the proposed Keystone XL pipeline.

Gas pipeline upgrades sound wonky and esoteric. But as New York has learned the hard way, they’re also a matter of life and death.