Walgreens will close about 1,200 locations over the next three years as the drugstore chain seeks to turnaround a struggling U.S. business that contributed to a $3 billion quarterly loss.

The company said Tuesday that about 500 stores will close in the current fiscal year and should immediately support earnings and free cash flow. Walgreens didn’t say where in the U.S. the store closings would take place.

Company leaders said the initial wave of closings will take place mostly in the back half of its fiscal year, which started last month. Walgreens will prioritize poor- performing stores where the property is owned by the company, or where leases are expiring.

Walgreens operates about 8,500 stores in the country and a few thousand overseas. All of the stores that will be closed are in the United States.

CEO Tim Wentworth told analysts Tuesday that the majority of its stores, or about 6,000, are profitable and provide the company with a foundation to build on. Wentworth became CEO of the Deerfield, Illinois-based company nearly a year ago.

Walgreens Boots Alliance Inc. said in late June that it was finalizing a turnaround plan in the U.S., and that the move may lead to hundreds of store closings.

The plan announced Tuesday includes 300 store closures approved under a previous cost-cutting plan.

Yet even the Walgreens stores that are performing well are not immune to broader challenges facing traditional drugstore chains, such as intensifying pressure from online outlets and dollar stores, said Neil Saunders, managing director of consulting and data analysis firm GlobalData.

Walgreens, like its competitors, has struggled for years with tight reimbursement for the prescriptions it sells as well as the rising costs of operating stores.

Rival CVS Health Corp. is closing 900 stores. Another major chain, Rite Aid Corp., emerged from bankruptcy protection this year after whittling its store count down to about 1,300 locations.