A recent whirlwind of rumors have said Amazon could be launching all kinds of new business lines, including cars and pharmaceuticals and that it’s interested in acquiring corporate messaging platform Slack. But the news today that Amazon is buying Whole Foods is the biggest surprise yet.

While the move may come as a shock to many (grocery chain investors have been particulary jumpy), it makes sense for Amazon on many fronts. Amazon reportedly considered a takeover last fall, so today’s announcement is the result of at least several months of due diligence and planning.

Whole Foods is a relatively cheap buy

First off, the Whole Foods acquisition comes at a fairly attractive price to Amazon. Whole Foods, whose annual sales are approximately $16 billion, has had seven straight quarters of negative comp sales and its stock has taken a beating. Even with the 27 percent premium Amazon is paying, the $13.7 billion acquisition price is lower than Whole Foods’ market cap from two years ago. In 2015, the market cap peaked at $20.5 billion, thus the market cap prior to this announcement was nearly 50 percent lower than that peak.

Whole Foods, once the “go to” for healthy and trendy items such as Kale and Chia Seeds, has faced increased pressure from rivals, including Kroger, Costco, Target, and Walmart, as they increase their selection of healthy and organic foods, while bringing prices down.

Competition from meal kit providers such as Blue Apron, and even Amazon itself have also led to a steady drop in sales. Whole Foods recently announced it would close nine stores and lower its sales forecast for the remainder of the year.

Despite the declining comp sales, Whole Foods still makes a healthy profit, and its profit margin percentage is higher than competitors such as Costco and even Amazon. The Whole Foods brand remains very strong among its customer base, primarily in North America.

Leveraging the store footprint

Amazon has been exploring groceries and delivering food for over a decade, and it has continued to test and expand initiatives such as AmazonFresh, Prime Pantry, AmazonFresh Pickup, Amazon Go, and recently Amazon Dash Wand. With the acquisition of the more than 460 Whole Foods stores in the U.S., Canada, and U.K., Amazon instantly has an opportunity to further test and expand on several of these initiatives, although many of these changes are unlikely to occur in the immediate future.

The store footprint, which Walmart has often viewed as a huge competitive advantage over Amazon, could potentially serve as a “mini fulfillment center,” allowing many more locations for AmazonFresh orders to be sourced from — and more locations for its AmazonFresh Pickup service. This could also help Amazon expand to more locations across North America beyond the current 14 cities, which are primarily focused only on highly densely populated areas.

Last year, AmazonFresh launched in London, and it is apparently launching soon in Australia. However, expanding AmazonFresh is capital- and resource-intensive and requires refrigerated warehouses and inventory. The acquisition of Whole Foods will make this expansion easier in new and harder-to-reach locations in North America.

Rather than Amazon building its own footprint from scratch, it would not be hard to imagine Amazon adding its Amazon Go technology to Whole Foods locations in the future. While Drew Herdener, a spokesman for Amazon, stated that Amazon has no plans to use Amazon Go technology to automate the jobs of cashiers at Whole Foods, Amazon likely never had the intention of building its own grocery stores, so leveraging this technology at a leading chain like Whole Foods would make sense.

Additionally, Amazon, like other tech conglomerates, has always been very focused on data. The insights into what products customers are buying at what times and in what locations could be very valuable as it continues to dive deeper into the $600+ billion US grocery store sales industry.

Amazon has been focused on growing its share of private label items, including those for foods, diapers, and laundry detergents. This acquisition now allows for shelf space to highlight and push its own brands to customers.

Amazon and Whole Foods are complementary

The Amazon Prime customer and Whole Foods customer look very similar. According to a report from Piper Jaffray, more than 70 percent of households that make more than $112,000 per year have a Prime subscription. Compare that to a Whole Foods customer, who similarly skews to affluence. And both have won over the sought-after millennial.

Additionally, while Amazon strives to be a one-stop shop for anything you need, its inventory selection and relationship with natural food brands could use a boost. Whole Foods provides access to increased selection and new brands that are not yet selling on Amazon. A combined presence could also provide increased bargaining power for Amazon with brands that already sell to both entities (hence, lower prices for customers).

Whole Foods has largely relied on outside parties, such as Instacart, for delivery to customers. Delivery has long been Amazon’s competitive advantage, so leveraging the refrigerated storage and inventory of Whole Foods with the delivery and inventory management capability of Amazon could yield a win-win-win scenario for Amazon, Whole Foods, and customers. What this deal means for Instacart is unclear, although some analysts like Cooper Smith view Instacart as a loser here.

Amazon has a track record of acquiring companies and letting them largely run independently, as it has done with Zappos, IMDB, Twitch, and several others. Several sources stated that Twitch turned down a higher buyout from Google because Amazon has a history of allowing independence for the companies it has acquired. And it’s worth noting that this deal comes just a few days after Whole Foods CEO John Mackey called activist investor Jana Partners “greedy bastards” amid pressure to overhaul Whole Foods’ operations or look for potential buyers.

Will it work?

The Whole Foods buy will be by far the largest acquisition Amazon has made yet, and we will soon have more clarity on Amazon’s approach. While many people will argue that Amazon is not in the business of brick-and-mortar and physical locations, its vision is “to be Earth’s most customer centric company.” Whole Foods is another opportunity to deliver this experience.

Given the opportune timing and Amazon’s decade-long ambition to provide customers groceries, I wouldn’t bet against Amazon turning this deal into a success. At the same time, Walmart has certainly kept busy over the past year with its acquisitions of Jet, ModCloth, and now Bonobos, and several big-box retailers have expanded their rollout of buy online/pickup in store offerings. In the midst of these moves, it is clear that the distinction of online vs. in-store is becoming increasingly blurry.

Fahim Naim is CEO of e-commerce consulting firm eShopportunity. He was previously a Category Manager at Amazon.