On Thursday morning, J.C. Penney (NYSE:JCP) reported that revenue fell more than 8% and adjusted EPS plunged 65% in the final quarter of fiscal 2018. On a shifted basis, comparable store sales fell 4% year over year.

At first glance, these results hardly seem like cause for celebration. Nevertheless, J.C. Penney stock skyrocketed on Thursday, rising as much as 31% and ending the day with a 23% gain. Let's look at why investors were pleased by J.C. Penney's earnings report -- and whether J.C. Penney stock could have more upside.

Results come in better than feared

Investors already knew before J.C. Penney's earnings release that the company was going to report another quarter of declining revenue and profitability. In early January, the struggling department store chain revealed that shifted comp sales slumped 3.5% during the key November-December holiday selling season.

Indeed, total revenue fell 8.4% to $3.8 billion last quarter, partly because of the 4% comp sales decline and partly because there was an extra week in the fourth quarter of fiscal 2017. This top-line result was roughly in line with analysts' expectations. J.C. Penney's operating margin contracted as well, largely because of a decline of more than 2 percentage points in the retailer's gross margin.

However, while adjusted EPS plunged to $0.18 from $0.51 a year earlier, analysts had expected adjusted EPS of just $0.11. Considering J.C. Penney stock has fallen from more than $10 just three years ago to between $1 and $2 for the past six months, investors were glad to see any sign that the company's troubles may be less than previously believed.

The exterior of a JCPenney store

J.C. Penney's fourth quarter earnings came in ahead of the analyst consensus. Image source: J.C. Penney.

Cash flow stays positive

Another driver of J.C. Penney stock's rally was that the company produced $111 million of free cash flow for fiscal 2018 as a whole. Furthermore, management expects free cash flow to remain positive in fiscal 2019.

To be fair, J.C. Penney includes asset sale proceeds in its free cash flow calculation, as my colleague Timothy Green recently noted. Excluding asset sales, free cash flow would have been negative-$33 million last year. Furthermore, the company reduced its inventory by more than 13% during fiscal 2018, leading to a $128 million improvement in working capital. In the long run, working capital gains are also an unsustainable source of free cash flow.

However, J.C. Penney expects just $20 million of cash proceeds from asset sales in fiscal 2019, so there will be much less distortion in its free cash flow metric. J.C. Penney also sees more room to reduce inventory, which will drive further working capital gains this year.

More importantly, inventory reductions don't just benefit cash flow in the year that they occur. By reducing its inventory, J.C. Penney won't have to put as many items on clearance at the end of each season -- and it won't have to discount them as much to get rid of them. As a result, the company's ongoing inventory reductions are paving the way for substantial gross margin improvement in the future.

Check out the latest earnings call transcript for J.C. Penney.

Looking ahead

On its two most recent earnings calls, J.C. Penney has given investors an idea about the potential upside from better inventory management. Getting clearance margins back to historical levels could improve gross margin by 2 percentage points. The company also has room to boost its gross margin by reducing shrink (i.e., lost and stolen merchandise). Between these two factors, the profit improvement opportunity for J.C. Penney totals hundreds of millions of dollars.

CEO Jill Soltau has made it a priority to improve the company's planning processes to avoid future inventory buildups. She also recently hired a new chief merchant and new senior executives to lead the planning and allocation and loss prevention teams. This influx of new talent should help J.C. Penney achieve its margin improvement goals.

Management doesn't expect to capture this entire opportunity in one year. The company needs to continue reducing its inventory in the first half of fiscal 2019. In addition, J.C. Penney's decision to exit the appliance market and stop selling furniture at most stores means that it will have to offer big discounts this quarter on items that had low margins in the first place.

An appliance showroom in a JCPenney store

J.C. Penney is selling off its appliance floor models this quarter. Image source: J.C. Penney.

J.C. Penney's gross margin was 32.5% last year, but as recently as fiscal 2015, it was 36%. J.C. Penney has a promising plan for returning gross margin to at least that historical level over the next couple of years. If it succeeds, that would boost annual earnings and free cash flow by $400 million or more.

In the long run, J.C. Penney still needs to prove that it can return to profitable growth. But even after last week's rally, its market cap is hovering around $500 million. Relatively modest improvements in its performance could justify a much higher price for J.C. Penney stock.