J.C. Penney (JCP - Get Report)   soared more than 22% Thursday after the long-struggling retailer posted stronger-than-expected fourth-quarter earnings and said it expects to be free-cash-flow positive in the coming year.

JCP shares rose as much as 31.5% to $1.63 Thursday morning before settling back to close at $1.52, up 22.6% on the day. The name rallied after Penney said earnings for the three months ended Feb. 2 came in at 18 cents per share, down 68% from the same period last year but 7 cents ahead of the consensus Street forecast.

Group sales were pegged at $3.67 billion, the company said, down 8.9% from last year and just shy of the $3.78 billion consensus collected by Refinitiv. Penney also said same-store sales fell 4% from the same period last year, a figure that beat the 4.3% analysts' estimate.

Looking into 2019, Penney said it would close 18 full-line stores, including three closures that were announced last month, as well as nine additional ancillary home-and-furniture stores. That will collectively cost the group $15 million in non-cash asset impairments and transition charges.

"As we forge a path to sustainable profitable growth, our decisions included eliminating non-core and low-gross-margin product categories, significantly reducing unproductive inventory and continuing the revitalization of our women's apparel business," CEO Jill Soltau said. "While we are pleased with these actions, we know we need to move faster to reestablish the fundamentals of retail, build capabilities focused on satisfying our customers' wants and needs and ensure that our digital and store operations operate seamlessly to provide an experience that wins with customers."

"We have much work to do to position J.C. Penney for success and create long-term value for our shareholders," Soltau added. "However, our unwavering focus and discipline is already enabling meaningful progress."

(This article has been updated.)