If you were waiting to buy McDonald's (NYSE:MCD) stock when investor pessimism made it an obvious steal, that window has passed. The fast-food giant has jumped more than 35% in 2017 and is currently the fifth best-performing stock on the Dow, not far behind Apple

Yet Mickey D's operating rebound goes deeper than simply accelerating sales gains, and so the stock has a good shot at outpacing the market from here.

Friends sharing a meal at a fast food restaurant.

Image source: Getty Images.

Growing for the right reasons

McDonald's is growing the hard way -- through increased customer traffic. Guest counts are up 2.1% over the past nine months compared to a slight decrease in the prior-year period. If the restaurant chain holds that pace through the fourth quarter, it will post its best result by that metric since 2011.

Chart showing improving traffic trends since 2015.

2017 is through the first three fiscal quarters. Chart by author. Data source: McDonald's financial filings.

Industry peers aren't doing nearly as well, which means McDonald's is winning market share in this tough operating environment. Both Shake Shack and Starbucks have seen their traffic fall into negative territory recently. These companies, and all its other rivals have major initiatives underway aimed at getting more customers in the doors. But only McDonald's is succeeding right now, and it is filling its restaurants across each of its geographic regions.

There's more profitability ahead

Investors can't expect earnings to grow at anything like the 55% spike that McDonald's announced in its third-quarter report. That figure was powered by an $800 million benefit the company achieved by selling off its corporate-owned stores in China. Notably, Starbucks is taking the opposite tack in the country, having just announced a plan to take full ownership of 1,300 cafes it had been jointly running with a local partner.

The initiative is part of McDonald's bigger plan to give up sales growth by selling off most of its company-owned locations to franchisees. In exchange, it's getting more of its revenue from stable rent, royalty, and franchise fees. The shift has already had a big effect on results this year. Sales are down 6% over the past nine months while profitability has jumped to 38% of sales from 33% a year ago.

MCD Operating Margin (TTM) Chart

MCD Operating Margin (TTM) data by YCharts.

McDonald's expects that margin figure to climb to the mid-40s by 2019 as the company continues selling off its locations to bring the percentage of franchised stores up to 95% from 85% at the start of 2017.

Bold plans and cash returns

There's nothing like a string of market share losses to force a management team to own up to some painful truths. "As customers' expectations increased," executives told investors back in March, "McDonald's simply didn't keep pace with them." 

In response, the company made big menu changes, including adding all-day breakfast, raised its food quality, and added a wide range of premium and value-based products.

Now that the company is reestablishing itself at the top of the industry, it's not about to give up that hard-won position. In fact, McDonald's will be making aggressive moves to increase food quality over the next few years while improving the in-store ordering experience dramatically. It could soon be one of the world's biggest delivery giants, for example, given that 75% of the population in its biggest markets live within three miles of one of its restaurants. That footprint will pay off as consumers increasingly choose to stay closer to home for their meals.

In the meantime, investors can sit back and collect a gusher of cash from the company. McDonald's has delivered $4.5 billion to shareholders through dividends and stock repurchases so far this year, which is just a small part of the $23 billion that it expects to pay out between 2017 and 2019.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.