Warning: This post contains spoilers for Captain Marvel.

Female mentorship is a running theme in Captain Marvel. Throughout the film, some of the title character’s closest, most meaningful relationships are with other women, from her longtime friendship with Air Force buddy Maria Rambeau (Lashana Lynch) to her playful, “cool aunt” bond with Maria’s daughter, Monica (Akira Akbar). Carol Danvers/Captain Marvel (Brie Larson) even gets her own female mentor in the form of Dr. Wendy Lawson (Annette Bening), a brilliant research scientist who’s secretly a Kree alien named Mar-Vell.

But Mar-Vell wasn’t originally written as a woman. Directors Anna Boden and Ryan Fleck, who co-wrote the screenplay with Geneva Robertson-Dworet, tell EW that their original drafts of the script had Mar-Vell written as a man, the way he was in the comics. They had already started looking for a male actor to play the part when they decided to make a last-minute switch.

“That was one of the epiphanies in the writing that came fairly late in the process,” Boden explains.

“Very late!” Fleck says with a laugh.

“Too late in the process for comfort, to be perfectly honest!” Boden adds.

Image zoom ©Marvel Studios 2019

The original Mar-Vell was a Stan Lee and Gene Colan creation from 1967, a Kree alien hiding among humans on Earth. (Marvel Comics created him and gave him the name Captain Marvel after the trademark lapsed for the original Captain Marvel, a Superman knockoff created in 1940 by Fawcett Comics. These days, that Captain Marvel belongs to the DC Universe and goes by the name Shazam, and he’ll soon be getting his own DC film starring Zachary Levi.)

Carol Danvers made her comics debut back in the ’60s as a love interest for the original Mar-Vell, and she gained her powers after being exposed to a radioactive Kree explosion. Original drafts of the Captain Marvel movie kept Mar-Vell as a key part of Carol’s origin story, but as the start of production approached, the filmmakers felt that the Lawson-Carol parts of the story just weren’t working.

“We had already started some initial casting discussions for an actor, a male actor to play Mar-Vell,” says Marvel Studios President Kevin Feige. “No one specific, but we’d started looking at lists. And we were struggling with it, frankly.”

It was Boden who suggested they cast a woman and combine the roles of Mar-Vell and the Supreme Intelligence, the all-encompassing cerebral force that rules the Kree and takes the form of a person its viewer admires most.

“Pretty late in the process of writing it, I think I just woke up one morning and I had dreamt it or something,” Boden explains. “I texted Ryan, and I was like, ‘Am I crazy that these could both be the same actor?’ And he was like, ‘Yes, you are crazy, and yes, you should talk to Marvel about it immediately.’ So it was a late-breaking idea, but something that I think helped pull those elements together in a way that it would’ve been hard to otherwise.”

They found their Mar-Vell and Supreme Intelligence in Oscar nominee Bening, who makes her superhero movie debut with Captain Marvel.

“We’ve just been big fans of her for a long time, and she’s got all those qualities,” Fleck says. “She’s got the great mentor quality that we were looking for in that character, but she can also be really tough, and that was really necessary for both aspects. She can be regal, which was perfect for the Supreme Intelligence, and she can also just be casual and cool and laid back, which was necessary for Lawson.”

Captain Marvel is in theaters now.

Related content:

Episode Recaps Previous All the Marvel Cinematic Universe movies, ranked By Chancellor Agard

See the best special edition toys coming to San Diego Comic-Con By Caroline Tew

The ultimate Marvel Cinematic Universe binge guide By Chancellor Agard

In honor of Captain Marvel, a pop-culture time capsule for 1995 By Mary Sollosi

See every Captain Marvel image released so far By Devan Coggan

10 Captain Marvel posters salute heroes, villains, and one stellar cat By Nick Romano

Captain Marvel trailer decoded: Brie Larson's superhero powers up By Devan Coggan

A guide to the many Captain Marvels over the years By Chancellor Agard

10 more female-led Marvel movies we'd like to see after Captain Marvel By Christian Holub

See 10 exclusive images from Captain Marvel By Devan Coggan Next