Note: This post contains spoilers for Wednesday night’s episode of “Riverdale.”

When actor Luke Perry died in March after having a stroke, “Riverdale” creator Roberto Aguirre-Sacasa assured fans that the writers would take their time to address the death so Fred Andrews, Perry’s character and the protective father of protagonist Archie Andrews (KJ Apa), could receive the send-off he deserved. Fred was said to be on a business trip for the latter part of the CW series’ third season, with Archie’s mother and Fred’s ex-wife, Mary (Molly Ringwald), stepping in to look after the teenager.

That living arrangement became more permanent when “Riverdale” returned for its fourth season Wednesday night with an episode titled “In Memoriam,” in which we discover that Fred has been struck by a car and killed in a nearby town. Archie receives the fateful phone call in Pop’s Diner, standing in the same spot where his father nearly died two seasons earlier. He falls to his knees in disbelief.

“Probably the most important episode of #Riverdale we’ll do this year, if not ever,” Aguirre-Sacasa tweeted back in June, sharing an image of the script’s cover sheet. “A tribute to our fallen friend. Thankful for this opportunity to honor Luke & Fred.”

“Riverdale” shed its campy, neo-noir skin in honoring the actor and his character, instead adopting a more earnest tone to highlight the qualities that defined Fred. He dies right before the Fourth of July, meaning that his body won’t be transported to Riverdale until after the holiday. Archie, in signature fashion, decides to take matters into his own hands and recruits best friends Veronica (Camila Mendes), Betty (Lili Reinhart) and Jughead (Cole Sprouse) to help bring his father home earlier. While doing so, he learns that Fred died doing what he did throughout his life: helping someone in need.

When the teenagers stop by the site of the accident to retrieve Fred’s truck, they encounter a distraught woman holding a bouquet of flowers. She reveals that one of her car’s tires had blown out at that spot days earlier, and that Fred had stopped to help her while other drivers continued to zoom by.

“We were working on the tire and a car just — it came out of nowhere, speeding,” she says to Archie. “I just froze in its path, and your dad, he pushed me out of the way. He saved my life. If he hadn’t done what he did, there’s no way I would be here right now. I know that."

The woman is notably played by Shannen Doherty, Perry’s longtime friend and former co-star on “Beverly Hills, 90210,” the ’90s teen drama that shot them to fame. In July, Doherty shared photos of herself with Perry on Instagram and wrote, “I am deeply honored to pay tribute to Luke on Riverdale. The care … this show takes in honoring his memory is beautiful. He is missed. Today. Tomorrow. Forever.”

Speaking to the New York Post, Aguirre-Sacasa noted that Perry had been trying for years to get Doherty a guest spot on “Riverdale” but that the timing had never worked out.

“We sent her the script, and she said, ‘I’d love to be a part of this,’” Aguirre-Sacasa said, adding that the episode “is a meditation on what Fred meant to the town of Riverdale and what Luke meant to the cast and crew — and the audience that grew up watching ’90210′ and the audience that watches ‘Riverdale.’”

The overlapping audience witnessed Perry’s maturation from the teen idol playing sensitive bad boy Dylan McKay on “90210” to the veteran actor who, both on and off screen, gave sage advice to similarly rebellious teenagers on “Riverdale.” Fred was the show’s moral compass and a steady source of support for Archie, a character often torn between his upstanding nature and his impulsive tendencies.

It is revealed in Wednesday’s episode, for instance, that the car that hit Fred wasn’t driven by the man who confessed to the crime, but by the teenage son he had been trying to protect. Upon learning this, Archie’s anger contorts into anguish. He realizes Fred would have done the same for him.

Doherty’s character reinforces this notion when she tells Archie that, even in the little time she spent with Fred, he “talked about you the entire time — his son, how he couldn’t believe that a man like him was blessed with such a thoughtful, kind boy.” We could say the same about Archie’s thoughtful, kind father.

Read more: