When you think about dead companies walking, BlackBerry was clearly one that came to mind, but under the leadership of CEO John Chen, the company is actually making a comeback as a software company focused on security, and it’s latest quarterly earnings report suggests the pivot is working splendidly.

The company reported revenue of $249 million, which shattered analyst’s expectations of $220 million, according to published reports. The surge was led by record software revenue, which came in at $996 million, a year-over-year increase of 26 percent. The company also reported record gross margins of 76 percent up from 67% last quarter and 62% a year ago.

CEO John Chen was justifiably pleased and Wall Street rewarded the company stock, which started the day at $9.90 per share and was sitting at $10.44 at the time of publication. It had been as high as $10.79 earlier in the day.

BlackBerry five year stock price snapshot. Chart: Yahoo Finance

All in all the company is trending in the right direction, something that seemed unthinkable a five years ago when BlackBerry was left for dead after its phone business went in the toilet, the victim of competition from iPhone and Android phones.

When Chen took over the company in November 2013, it seemed he was on a fool’s errand trying to save a company that had little chance in the handset market, but one thing the company had was some cash on hand from its glory days as a popular handset maker. Chen has used that cash for strategic purchases that have helped redefine the company.

Chart: Crunchbase

Prior to his coming on board, BlackBerry was a company taking on water. It had watched its phone marketshare get hacked. Set the wayback machine for 2009 and you’ll see a company that was firmly in control of the smartphone market, according to data from comScore (BlackBerry was known as RIM in those days):

Chart: comScore

Fast forward four years to December 2013, the month after Chen took over and the market had shifted dramatically:

Chart: comScore

If you looked at the company purely from a phone perspective, it didn’t seem to have much left, but Chen obviously saw a way forward for the company and he began to reshape it slowly but surely. The report today is just a one-quarter snapshot, but it’s one that shows companies can rally from seemingly unrecoverable situations.

While Chen admitted to CNBC, that there could be bumps in the road ahead, BlackBerry has redefined itself as a software company, and once again the future looks bright. That didn’t seem possible all that long ago.