When Borders folded three years ago, Barnes & Noble (BKS) was supposed to already have one foot on the grave. Bookstores across the country were failing thanks to the rise of Amazon.com (AMZN -2.56%), which came to primacy first as the leading online physical book retailer and later through its monopolistic position in e-books.

In 2011, Barnes & Noble reported its first annual loss in ages -- of $74 million -- as several years of declining same-store sales took their toll. Stores were gradually being shuttered, and the company's future was uncertain at best as it staked its fate largely on the NOOK e-reader.

The intervening years have been equally rough for B&N -- revenue fell more than 10% over the last two years, and same-store sales continued to drop, down 5.8% last year.  

Still, the company has been making improvements through cost-cutting, a better merchandising strategy and product mix, and other changes, and managed to increase its gross margin by 450 basis points last year to 29.1%. Because of that change in direction, Barnes & Noble is actually on track to turn a profit this year for the first time since 2010.

In its first quarter, which ended August 2, sales declined 7%, but per-share loss narrowed from $1.56 to $0.56. Comparable sales, excluding the flagging Nook unit, were essentially flat, falling by just 0.4%. While the first-quarter loss may seem significant, investors should be mindful that the company's business is highly seasonal, as it makes its profit in the fall and winter quarters when students buy and rent textbooks from its college stores and its retail stores benefit from the holiday shopping season. 

Not just a bookstore anymore
A different approach to merchandising has been a big part of Barnes & Noble's comeback. Its Toys & Games and Gifts segments have helped boost gross margins and buffer the slide in same-store sales. Last year, Toys & Games delivered a 12% comp during the holidays. This holiday season, the retailer appears to be doubling down on the strategy, making the most out of its high-trafficked properties. Among other tactics, the company is featuring a "10 Most Inspired Gifts" table at its stores, which are likely to appeal equally to booklovers and philistines. The table includes items such as a popcorn maker, a craft beer kit, and turntables.  

The company hasn't forgotten about books, either. To encourage customers to visit its stores this holiday weekend, the bookseller is offering 500,000 signed titles from big names such as Hillary Clinton, George W. Bush, E.L. James and Dan Brown. The idea, which received a "hugely enthusiastic" response from the publishing community, underscores another hidden advantage of Barnes & Noble's. In the wake of Amazon's dispute with Hachette, the online behemoth has only become more reviled by publishers and authors, who do not want to see it monopolize and commoditize the book business. It's in their interest that Barnes & Noble survives and thrives, and they will support it to a reasonable extent. While that doesn't guarantee Barnes & Noble's success, it certainly helps to have suppliers in your corner. Google also recently added its name to that list, partnering with Barnes & Noble to offer same-day delivery of books in a few major cities. The program is just in pilot mode currently, but it should further bolster B&N in its fight against Amazon.  

The coming split
Barnes & Noble's state of flux will climax when the company divides itself into two separate units next year, as the retail stores and barnesandnoble.com will split from the college stores and the NOOK media division. The board expects the separation to be completed by the first quarter of 2015. In preparation for the separation, the retailer is downsizing from its 208,000 square-foot campus in Palo Alto, which it expects to result in a reduction of $9.6 million to net annual occupancy expenses and remove a $102 million lease obligation, further shoring up its financial situation. 

Investors cheered the decision to spin off the NOOK unit, which seems to give the retail stores their best chance at prospering as NOOK results have been dismal of late -- though the healthy college bookstore unit will also be spun off in the process.

With comparable sales flattening and a smart merchandising strategy for the holiday season ahead, Barnes & Noble may have finally made it out of the woods. Analysts are expecting a per-share profit of $0.18 for the full fiscal year, which would be its first since 2010, and the stock is trading at a five-year high. With pressure continuing from Amazon, the retailer is unlikely to ever revisit its glory days, but it also seems to have put its darkest days behind it. If core comps turn positive this holiday season, the stock could have more room to run ahead of it.