Sometimes a TV show gets a goodbye just right: Sam telling Diane to "have a good life" in Shelley Long's final episode of "Cheers"; Eric's parents pushing him out of the driveway in Topher Grace's final episode of "That '70s Show"; and Finn singing "Don't Stop Believin'" one more time with Rachel in the late Cory Monteith's final episode of "Glee."

The exits of Long and Grace, of course, were planned. The actors had opted to leave their still-running shows; both, in fact, would return to their respective series as guest stars.

Monteith's farewell was different: It wasn't planned. It wasn't anticipated. But it was as perfect as any scripted departure.

Almost perfect, anyway.

Monteith, who was found dead of an overdose in a Vancouver hotel room on July 13, made his final "Glee" appearance in the episode "Sweet Dreams," which first aired April 13 (and which you can watch in full below). The storyline had Finn belatedly heading off to college. By episode's end, Finn is focused on earning a teaching degree and rejoining Mr. Schuester (Matthew Morrison) as an equal partner in McKinley High's New Directions.

If that's all there was to it, it would've been a fitting endnote, in a way, for Finn's character; football-playing Finn, after all, was Schuester's prize recruit in the "Glee" pilot all those years ago (which is how far back 2009 now seems).

But that's not all there was to it.

On-again, off-again Finn and Rachel (Monteith's real-life girlfriend, Lea Michele) reconnect via the phone. She tells him about her "Funny Girl" audition; he tells her to "do something that takes you back to the roots of your passion." And so she sings "Don't Stop Believin'," just as she sang "Don't Stop Believin'" on the "Glee" pilot. Midway through, Rachel's old gang shows up in spirit and in red shirts — Kurt, Mercedes, Tina, Artie, and, on drums, Finn. The scene is meant to recall Rachel's origins; now it recalls ghosts.

Remember our show, it asks, before we stretched ourselves into a million plot lines? Remember our show when it was bursting with promise? Remember our show when it was about these core characters? Remember the "Glee" pilot all those years ago?

For Monteith, the episode, with its closing of circles, with its celebration of the power of a Journey cover, was a perfect sendoff.

Almost perfect, anyway.

"Sweet Dreams" wasn't supposed to be Monteith's last episode, not of this past season, and not forever. Monteith was supposed to be back on "Glee" come the fall; he was supposed to be alive.

There's nothing perfect about how "Sweet Dreams" came to be Monteith's final "Glee." Sometimes, however, even when it's not trying, a TV show gets an ending just right.