Star Wars: The Last Jedi is dedicated to the irreplaceable Carrie Fisher, for whom the credits reserve a special place “in loving memory of our princess.” Fisher’s final appearance as General Leia Organa was not meant to be her last. And yet, by pure chance, The Last Jedi stands as the most fitting farewell to her imaginable, a moving tribute to both the iconic freedom fighter and the woman who gave a galaxy hope.

Fisher’s untimely death last December came as The Last Jedi was five months into post-production; by then, all her scenes had been filmed (it didn’t affect anything onscreen) and a major role for Leia had been planned for Episode IX, as Fisher had hoped. Those plans have since been scrapped, with Lucasfilm president Kathleen Kennedy vowing not to recreate the General digitally and to rewrite her out of the film instead.

Which leaves The Last Jedi as an unintentional final monument to Fisher and Leia. Incredibly, it’s a flawless one in that capacity.

Fisher’s performance in The Last Jedi is not only one of her best, it’s also filled with moments that indirectly recall her real-life legacy. Her relationships, her wit and candor, and a portentous sense of mortality, especially in two poignant farewells to old friends, imbue many of her scenes with special meaning. For writer-director Rian Johnson, who counted Fisher not only as a collaborator, but as a friend, watching her performance now is a complex experience.

(Warning: Discussion of specific plot points for The Last Jedi follows—turn away now if you haven’t seen the film and want to go in blind!)

There’s a scene in The Last Jedi when, after many bleak years spent apart, Leia and her twin brother Luke Skywalker (Mark Hamill) finally reunite face to face—or at least, face to Force. Leia cracks wise about having changed her hair since they saw each other last (a line Fisher wrote herself), and forgives Luke for disappearing to the planet Ahch-To after failing her son, Ben.

They mourn the loss of Han Solo, the love of Leia’s life. Then Luke hands her Han’s lucky golden dice, the same ones that hung in the cockpit of the Millennium Falcon. “No one’s ever really gone,” he says as Leia looks down at the dice in her hand—a line meant to fortify Leia for what’s to come, but which also, unintentionally, comforts those still reeling from Fisher’s death.

It’s a gut-punch moment, not least because it’s the first Luke and Leia have shared onscreen since 1983’s Return of the Jedi—and now the last they ever will—or because Hamill still speaks of Fisher as “like a sister” to him in real life. Even on set the day it was filmed, Johnson tells The Daily Beast, watching the hallowed scene unfold felt momentous.

“It’s bizarre because, you know, obviously we didn’t know that it was gonna be a farewell scene,” he says by phone from Los Angeles the day of Last Jedi’s release. “And it’s odd because I remember when we were shooting the Luke-Leia scene, it felt like church on set. It was usually a jovial set, you know, a really happy, bouncy set. And that day, everyone was just quiet and just watching these two.”

“It was like a hush over the whole set,” he says, “it really did feel like church. I remember there being a weight to the whole thing and we all just felt like, we’re seeing something really special happen. In a way that it never, ever was on the set for us. There was, very weirdly, weight.”

Leia’s last words of encouragement in the film, addressed to Daisy Ridley’s Rey, take on similarly heightened emotion in light of Fisher’s death. (As does the onscreen presence of her real-life daughter, Billie Lourd, in her role as Lieutenant Connix.) With the Resistance decimated and key leaders gone, Rey asks, “How do we build a rebellion from this?” Leia responds with calming certainty: “We have everything we need.”

“Now when I watch [Fisher’s performance], of course, it’s…” Johnson begins, trailing off. “I mean, it’s complicated. It’s very complicated. I feel very—God, I feel lucky, you know? I feel lucky to have this performance from her, I feel lucky we had those moments with her. I feel so lucky that her last moments in the movie, which are at the very end of the movie, are words of hope given to Rey, given to us. Yeah. God. I wish she was here to see it.”

Fisher brought more than gravitas to The Last Jedi, of course. She also brought a famously razor wit, one whose input Johnson was eager to work into the screenplay. During a panel discussion at Star Wars Celebration last April, he described the madcap artistic process of tinkering a script with her.

“She is a brilliant writer, an incredible mind,” he said. “I would go to her house. We would sit on her bed for hours and go through the scripts. We would have these stream of consciousness jazz poetry kinda ad lib sessions. I would just scribble on my script everything she said, and at the end of six hours, there would be like a four-word line of dialogue that was the distillation of all of that that was brilliant.”

Fisher’s fingerprints—and her dry, acerbic sense of humor—are all over the film. “She loved one-liners and jokes,” Johnson laughs. “She could just pop out so many jokes. So the whole thing where she sits down with Luke and [says], ‘I changed my hair,’ obviously, that was her.”

Another moving, funny moment, in which Leia bids goodbye to Vice Admiral Amilyn Holdo (played by a violet-haired Laura Dern), also benefits from a personal touch. “So much loss,” Leia says wearily at losing yet another lifelong friend. “I can’t take any more.”

Holdo smiles knowingly. “Sure you can,” she says. “You taught me how.”

The line, it turns out, was Dern’s own invention, channeling her deep admiration of Fisher and echoing the generation of fans who looked up to her. What comes next, Johnson remembers, was Fisher’s idea: Holdo attempts Star Wars’ timeless sign-off, but falters. “May the Force…” she starts, her voice breaking. Leia volleys back without missing a beat: “You go, I’ve said it enough.”

“And then they both say, ‘May the Force be with you, always’ together,” Johnson remembers. “That was Carrie, too.”

“That whole Holdo scene, that goodbye scene was actually completely rewritten with Carrie and with Laura,” he explains. “The three of us got together and worked through it. And the real heart of that scene came from Laura. It was her saying, ‘I just feel like, from my character to Leia, but also me to Carrie, I want to express what she means to me. I want to express my gratitude.’

He adds, “That’s one that may be the most powerful, oddly for me, especially now watching them. I’m just so happy we were able to get that.” A galaxy of fans is too.