Best Buy Co., the giant in retail electronics that just a few years ago having major problems, is bucking the retail slump in the U.S. by turning its stores from a drag on business into ways to fight off online rivals such as Amazon.com.

Thursday, the company posted a small increase in its quarterly revenue, which surprised investors who had been expecting a decline. Online U.S. sales jumped by 23% from the same period one year ago, representing $1 billion of its business for the quarter and offsetting drops in sales in-stores.

Shares of Best Buy surged on Thursday by 21% to reach a new high of all time in marking the biggest percentage gain in over 16 years.

It showed a huge reversal for the company that just five years ago experienced plunging sales while its profits dwindled as consumers browsed at their brick and mortar locations but purchased online through Amazon or other websites, which is called showrooming.

Several investors are still skeptical with over $2 billion in shorts – bets that expect the share price to decline.

The modest growth by the company helped it to stand apart from the rest of an industry that is struggling with declining traffic in malls and a glut of the traditional stores.

Retailers are now on a pace to close record numbers of stores in 2017 and several have been liquidated after filing for bankruptcy. Two of the biggest competitors of Best Buy, hhgregg Inc. and RadioShack recently filed bankruptcy and have plans to shutter hundreds of their stores.

Best Buy did close 12 of its large stores as well as 40 small ones the past year, but continues operating 1,600 locations across North America and is able to use more and more of them to build up its growing e-commerce business.

Close to half of its orders online are picked up or shipped from one of its stores.

To fight off its competition online, Best Buy ended efforts made to charge customers more in its stores than online. In 2013, it promised to match competitor’s prices online and brought prices in line with those of Amazon, a move that has seen big dividends as shoppers now can check prices instantly online on their mobile handsets.

The price match guarantee has made many loyal shoppers who are now returning to Best Buy locations, checking comparable prices and purchasing their electronics in store.

Get Analysts' Upgrades and Downgrades Daily - Enter your email address below to receive a concise daily summary of analysts' upgrades, downgrades and new coverage with MarketBeat.com's FREE daily email newsletter.