Rite Aid (RAD -20.53%) has been an investment darling over the past year as it continues to boost its profitability and play catch-up to competitors CVS Corp. (CVS -1.35%) and Walgreen (WBA -0.69%).

Shares in Rite Aid have more than doubled since last fall thanks to an aggressive restructuring that's shuttering unprofitable stores and reimagining the brand as wellness centers. Since its shares have been on such a tear, let's take a closer look at last quarter's earnings and see what's behind the move higher.

RAD Chart

RAD data. Source: YCharts.

Turning the freighter
Not long ago, Rite Aid was posting losses year after year as it struggled under the weight of an aging retail footprint and a big debt load following its 2007 acquisition of pharmacy chain Eckerd.

RIte Aid's mounting losses essentially sidelined the company as competitors CVS and Walgreen branched deeper into the prescription supply chain and expanded into primary care services with in-store clinics. In order to get the company back on track, Rite Aid embarked on an aggressive restructuring that may serve as a case study for future struggling retailers.

In the past three years, it has shifted its focus from top-line sales growth to profitability, jettisoning stores and embracing an aggressive rewards program to boost foot traffic and front-end sales.

The plan is paying off. Rite Aid's store count has shrunk from nearly 4,800 in fiscal 2010 to a shade more than 4,600 exiting December, yet sales have remained mostly unchanged. The company reported revenue of $25.7 billion in fiscal 2010 and $25.5 billion exiting fiscal 2014. For fiscal 2015, Rite Aid expects sales will exceed $26 billion -- not bad for a company that has reduced its store count by more than 4%.

RAD Revenue (Annual) Chart

RAD Revenue (Annual) data. Source: YCharts.

Leveraging the bottom line
The company's acquisition of Eckerd Pharmacy for more than $3.3 billion in 2007 strained its balance sheet and saddled it with a larger but older retail footprint. The Eckerd deal increased Rite Aid's store count by 1,500 stores, strengthening market share in its decidedly East and West Coast-based territory, but failed to deliver on Rite Aid's hopes for profit-friendly synergies.

At the time, Rite Aid expected the Eckerd deal would be accretive within 12 months and would better position it against market share leaders CVS and Walgreen. Instead, integration struggles kicked off a series of money-losing years leading to losses of more than $3 per share in 2009 and a share price south of $1 per share.

That dismal performance sparked the company's turnaround plan, and, while investors remained mostly unconvinced, Rite Aid's losses steadily improved culminating in a full-year profit of $0.12 per share in fiscal 2013. The earnings momentum continued this past year, with the company reporting full-year fiscal 2014 earnings of $0.22 per share.

RAD EPS Diluted (TTM) Chart

RAD EPS Diluted (TTM) data. Source: YCharts.

Planning for the future
Rite Aid's success stems from a series of tough decisions. It restructured its debt, which helped lower its interest expense from $127 million a year ago to $102 million last quarter. The debt restructuring has also eliminated worries over major debt maturities until 2018.

In addition to restructuring its debt, Rite Aid's aggressive store closing, remodeling, and relocating program has also paid off. Rite Aid's EBITDA margin has expanded from 3.6% in fiscal 2012 to 5.4% exiting last quarter and the company's free cash flow has jumped from just $45 million in 2012 to $280 million.

Now, with the company standing on firmer financial ground, Rite Aid is turning its attention back toward top line growth. While it only spent $16 million on remodels in 2010, it spent $180 million on them last year and plans to spend $225 million on them this year.

In addition to refreshing its remaining stores, Rite Aid is also finally jumping into the retail clinic business with its acquisition of RediClinic, a 30 clinic chain in Texas that operates in H.E.B. grocery stores. That deal is likely the first move toward expanding Rite Aid's flu and immunization shot program to also include in-store primary care services. Such clinics have been a success for CVS and Walgreen, which already operating hundreds of clinics in their stores.

But the deal isn't just strategic for its ability to jump start Rite Aid's services offering. The acquisition also gives Rite Aid entrance into the important Texas market, which is home to many retirees.

Fool-worthy final thoughts
Rite Aid expects profit to increase again this year, and for sales to eclipse its 2010 levels. While the company is still carrying a lot of debt, it's far healthier now, suggesting Rite Aid may be able to refinance its 2018 debt maturity at more favorable terms before it comes due.

That's not to say there aren't remaining challenges facing the company. Rite Aid continues to trail CVS and Walgreen in integrating primary care into pharmacies, and Rite Aid is absent in key retirement markets like Florida.

As a result, it wouldn't be shocking to see Rite Aid leverage RediClinic as a way to enter the pharmacy market in both Texas and Florida in the future. In the meantime, it appears investors will continue to be rewarded given Rite Aid expects it will earn between $0.31 and $0.42 per share this year.