Lionsgate and Starz are once again at the altar.

After years of flirting with a merger, the studio and cable programmer are nearing a deal whereby Starz will be acquired by Lionsgate. Teams from both companies have been working furiously in the past three days to hammer out details of the proposed union. There are still significant stumbling blocks that could derail a pact. Among them are tax issues, the mechanics of investor and matchmaker John Malone’s super voting rights, management incentives, and the two media companies’ volatile stock prices, according to insiders. Investor concern about the viability of the media industry and the fallout from the United Kingdom’s vote to leave the European Union have further depressed shares.

A potential agreement would come nearly 18 months after the two companies were brought together by Malone and four months after Starz disclosed in a regulatory filing that it had been approached by Lionsgate about negotiating an acquisition.

Investors have been anticipating a union of Lionsgate and Starz ever since Malone connected the two media companies in February 2015 by swapping a 4.5% stake in Starz from his personal holdings in the pay TV group for a 3.4% stake in Lionsgate and a seat on the company’s board. That move was widely seen as Malone engineering a future combination of the entities. Malone is the largest shareholder in Starz with holdings that are part of his personal portfolio and separate from his Liberty holding entities.

Talks have heated up at various points, but a deal failed to materialize earlier this year after Lionsgate’s stock tumbled following disappointing results from the final installment of its “Hunger Games” franchise.

Lionsgate’s shares come with 14.5% of the voting power in Starz.

Starz shares rose on last week’s news of Lionsgate’s latest overture. The company has a market cap of about $2.8 billion. Lionsgate and Starz have explored the idea of merging in the past, even before Malone played matchmaker, but valuation was said to have been a hurdle.

Starz had been part of Malone’s Liberty Media until late 2012 when it was spun off as a stand-alone public company. The group of 17 Starz and Encore-branded linear and on-demand channels has been on the block since then but has had few takers amid a time of uncertainty in the MVPD and cable programming arenas.

Malone deepened his ties to Lionsgate late last year when Discovery Communications, in which he holds a significant personal stake, and Liberty Global, the international cable unit, acquired a 6.8% stake in Lionsgate for a total of $390 million. As part of that deal, Discovery CEO David Zaslav and Liberty Global CEO Mike Fries joined the Lionsgate board.

Starz has significantly stepped up its original programming offerings in the past two years under the direction of CEO Chris Albrecht and has gained ratings traction with shows including dramas “Outlander” and “Power.” But Starz has faced an uphill climb in trying to transition from a focus on theatrical movies to original series at a time when it faces exponentially more competition than just from established rivals HBO and Starz.

Lionsgate’s film and TV production operations would be a natural fit with Starz’s need for high-end programming and Lionsgate’s success in producing shows such as “Orange is the New Black and “Mad Men.”

It’s unclear how the merger would impact Lionsgate’s involvement in Epix, the pay TV network that it co-owns with MGM and Paramount.

The Starz group launched in 1994. It grew to become a contender against HBO and Showtime for studio theatrical output deals, but as the on-demand availability of theatrical titles expanded, Starz has shifted its focus to investing in original series. Disney and Starz ended their output contract at the end of last year (although 2015 titles including “Star Wars” will continue to air on Starz for another year). Sony Pictures is the last major Hollywood studio with a Starz deal.

Lionsgate’s movie division has been struggling with disappointing results from releases including “Now You See Me 2” and “Gods of Egypt.” After years of success with film series such as “Twilight,” “Hunger Games,” “Saw” and the Tyler Perry comedies, Lionsgate has been slow to develop new franchises.

Brent Lang contributed to this report.