Life as a male chick has never been ducky. Instead, the lives of newborn males in egg production facilities have been short and grim. But that sad era will finally come to an end, reports Ben Rosen for Christian Science Monitor. A new technology makes it easier to ID a chick’s sex before they’re born, allowing egg producers to pledge to do away with the grisly practice of culling male chicks.

When it comes to industrial egg production, male chicks are unwanted. Since they don’t lay eggs or grow large enough to become broilers, they are persona non grata for hatcheries, and only a few survive to become breeding roosters. Until now, standard operating procedure has been to do away with male chicks after they hatch and can be sexed.

The chicks are euthanized using carbon dioxide gas or what is known as “maceration,” a process used on chicks up to 72 hours old. According to the American Veterinary Medical Association, this method uses a “specially designed mechanical apparatus having rotating blades or projections, [causing] immediate fragmentation and death.” Translation: The majority of male chicks are ground to death before they reach three days of age. As Elisabeth Braw reports for Al Jazeera America, the several hundred million male chicks culled each year are then used as animal feed.

Though organizations like the AVMA claim that maceration is the most humane method of disposing of male chicks, undercover videos of maceration have inspired protest, Rosen reports. But the economics of culling have made the practice hard to abandon, until now.

On June 9, United Egg Producers, an egg-farming co-op that owns approximately 95 percent of the United States’ egg-laying hens, announced that it would do away with the practice. In a statement by The Humane League, an animal rights advocacy group that worked to secure the commitment by UEP, culling will stop “by 2020 or as soon as it is…economically feasible.”

Instead of killing male chicks once they’re born, producers will simply identify males while they’re still inside the egg, then dispose of them before they’re born. The most promising technology was generated by German scientists and can ID a chick’s sex within nine days of incubation by using spectroscopy to analyze blood cell development that points to male or female eggs. As The Poultry Site reported in 2015, the male eggs that are discarded can in turn be used as animal feed or for other industrial processes. Rosen writes that other options, like injecting genes that make male eggs turn a different color than females, are being investigated, too.

Ending the disposal of male chicks is a sea change for industrial egg production, and it comes on the heels of sweeping legislation in states like California that has made cage-free eggs both more popular and more expensive.

But why not simply sell the fertilized eggs? As an American Egg Board representative tells Chowhound, only very few fertilized eggs ever make their way to store shelves. By nine days of development, the earliest the sex can be tested, a chicken egg contains a recognizable embryo, which would render it impossible to sell in American stores.

Perhaps in the future, technology will make it easier to detect males in the first days after fertilization. But for the hundreds of millions of male chicks who will make their way to the grinder before the UEP enacts its promise, even an imperfect solution is better than the status quo.