The Star Trek franchise emerged on television screens in 1966 and — well, it wasn’t an overnight success, but it’s become a cultural touchstone since. From Captains Kirk to Picard and back to Kirk again, Star Trek has set the tone for science fiction for decades.

But it got off to a rough start. In 1964, the show’s creator, Gene Roddenberry, produced the pilot episode of the series, called “The Cage,” featuring a Captain Christopher Pike. The picture above comes from that episode, and the fact that the captain you’re probably familiar with is named James T. Kirk probably tells you all you need to know about how the pilot fared. NBC executives found it too cerebral and, well, kind of boring, and decided not to move forward with the concept as-is.

Normally, that would be enough to sink a fledgling television show. But in this case, Roddenberry and team got a second chance: the network requested a second pilot, one starring William Shatner as Captain Kirk. NBC liked that episode, titled “Where No Man Has Gone Before,” and the rest is history. For three years, Star Trek bent the boundaries of space travel, bringing science fiction into family rooms everywhere. But “The Cage,” well, it seemed destined to never grace our television screens.

Instead, it helped save the show.

Star Trek’s ratings during its first run were never all that good, and NBC was often on the fence as to whether to renew it. (It almost canceled the show after two seasons but a letter-writing campaign saved it for a third.) The show had a very long and expensive production cycle because of its reliance on special effects — firing phasers, launching space torpedoes, beaming the captain to an alien planet, and flying through space generally all required some additional magic. This caused delays in getting a completed product out the door and at a price tag higher than the studio wanted to pay.

As that first season continued, the show fell further and further behind schedule. Ultimately, this problem became a critical one — the show wasn’t delivered to NBC until Tuesday despite airing two days later. That wasn’t a lot of wiggle room and the network was getting understandably concerned.

Roddenberry came up with an idea. What if, he surmised, he could create a two-part episode which took only one week to produce? That seemed like an impossible task; you can’t simply create twice the product without upping the work — unless you can tap into already-completed work. “The Cage,” Roddenberry reasoned, was just collecting dust; why not use it to save the production team a lot of time and money? The mothballed pilot episode was used as the backstory for this two-part adventure, putting the show back on track. “The end result of this approach,” as StarTrek.com explains, “was that the production company was able to essentially film one episode and, using major parts of ‘The Cage,’ stretch it into two.” And just like that, “The Cage” made its way on air after all.

“The Menagerie,” despite only coming to be because of a budget and time crunch, is now regarded as one of the best episodes in the series. As for “The Cage,” it got to see the light of day in its own right. Due to the popularity of Star Trek overall, The Cage made its TV debut in 1988 as part of a two-hour Star Trek retrospective.

Bonus fact : In the original concepts for the show, Spock was a Martian, not a Vulcan. Roddenberry changed his mind, though. As Wikipedia explains, “Due to Roddenberry’s concern that a Mars landing might take place before the end of the series, Spock’s home planet was changed.” To date, that concern has not come true.