It hasn't been the best new comedy of the season (I leave it to the warring "Community" and "Modern Family" factions to battle that title to the death), but no show on television demonstrated a more impressive learning curve over the course of a season than ABC's "Cougar Town," which airs its next-to-last episode of the season tomorrow at 9:30.

What began as a sitcom that lived up - or down - to its title instead morphed into a charming, goofy ensemble comedy. Instead of chasing after younger guys and obsessing over wrinkles, Courteney Cox's Jules is now playing den mother to a weird surrogate family in her cul de sac, trying to pass the time by drinking wine, pranking each other, writing songs and inventing silly games like the elegantly simple Penny Can.

The season's final two episodes deal with Jules' son Travis (Dan Byrd) graduating from high school, and with the new relationship Jules started with neighbor Grayson (Josh Hopkins), and I spoke with the show's co-creator, Bill Lawrence, about the abrupt and impressive hard right turn the series took about a third of the way into the season. (There's also the obligatory "Scrubs" talk at the end.)

We talked back in January about how you realized that the initial premise of Jules sleeping with younger guys wasn't working and shifted things in more of an ensemble direction. Was there any resistance from the network, the studio, or even from Courteney, given that the original premise was all about her?

The network and the studio and Courteney have really enjoyed the quality of the show. I think it was hard for everybody not to acknowledge that the show's creatively gotten stronger. Putting aside the fact that the reviews have been nicer, crews have been laughing more, cast has been laughing more, so we have a better idea of what's working. Courteney knows this show survives as an ensemble, and what has kept things fine is, if you look at every eopisode, she still gets five lines to everyone else's one, three jokes to everyone else's one. Jules is the only character who has an A-story in every episode, and she's involved in everyone else's story. I like to tell her that Tina Fey and Mike Fox and Zach Braff were all in ensemble shows, and she gets to do more than any of them. I think  the new model for a star-driven show is a star-driven ensemble.

So if you were pitching the show to the network today, as it is now, what would that pitch sound like?

"Courteney Cox is the matriarch of a dysfunctional group of friends and family." But then I'd have to spice things up, ask, "What's the big conflict in her life? She's in her 40s and has a teenage son and has re-entered the single world..."

Would that show be as likely to get picked up as what you actually pitched last year?

I doubt it. I only say that just out of interest. I've been trying to keep track of what pilots are hot. It seems that, right or wrong, everything has a conceit. Having been through a lot of pitch meetings, it's almost impossible to pitch, "It's about a funky group of friends." I'd have to make it sound like it had a hook: "There's a group of people who all live in the cul de sac, their lives are intertwined, they all know way too much about each other." I'd have to make it almost like a conceit that they happen to live in the same neighborhood. But the days of going in and saying, "Hey, it's a bunch of poeople who work and hang out in a bar, and it's called Cheers," those days are over.

Well, as someone who's been in the comedy business for a while, do you think that's a good thing?

I don't. I think it's always very weird when television comedy chases the idea when it should be chasing execution. I read some logline for "a really conservative Ann Coulter-like talk show host is really messed up in her personal life." Why can't it just be there's a really cool, interesting female character? I  think feature films sell on the idea, and I think TV works based almost entirely on execution. I don't think anybody is going, "Wow, that show is executed poorly, but the idea is so cool I just have to keep watching."

So now that the show has moved so far from the original idea, what are you going to do about the title?

I'd like to (change it), and the studio has been talking about it for three reasons: One, partly as a result of common sense and partly from their research, they find too many instances of testing of people saying they would never watch a show called "Cougar Town" - "I don't want to see some show about a 40-year-old woman nailing younger guys" - and then they screen an episode, and people go, "Oh, I would watch this show." Second point is simply what you already said, which is you would be hard-pressed to watch the last three episodes of the show and  asked anyone for titles - I doubt anyone would say "Cougar Town." Third, in a world where ABC and Steve are looking to promote "Modern Family" and capitalize on it to promote all their new shows next fall, anything you can do to create some kind of dialogue about your existing show is smart and savvy.

The reasons not to do it I think solely come down to business reasons.

So what would you change it to?

I always joke that the show should be called "Friends  and Neighbors," but the "Friends" part should be written in the same font as Courteney's old show. But I don't want to put 'em out there yet. It's tough, man. I always own up to mistakes. It's a great hindsight mistake. If you had showed me an episode of the show back when I wrote the pilot, I would say, "There's no way that's the same TV show." I have never been on a show that changed so much creatively so quickly.

Yeah, I can't think of many that made such a dramatic shift so early in the process.

It's two things: The cast is funny, the writers are funny, and when you write a new show, all television shows, they take six episodes to find the show. The first six episodes are a search. It's not just, 'Hey, we're going to change this.' It's 'What's working, and what's not? Let's write to what's working and away from what's not.' In our show, the stuff that hooked us to the initial concept and title was not working as well as the other stuff. I found myself much more interested in Courteney as a mom, when she and Dan Byrd work togther, it slays me. I like how she works off of other people. Also, the harsh reality of week-to-week television production. When you have seven regular castmembers, and she's going to date a younger guy every week, and it's not a superstar, so he'll be cheap, 'Let's see if we can find an interesting 26-year old who's charming and funny and available and can work for our budget." And not too many of them out there.

One of my favorite parts of the redirected show is how we now just see these people who are so bored with their regular lives that they're always trying to come up with some new game or running joke to keep themselves interested, like Penny Can. Where did that come from?

One of the things that I always try to go back to, there are writers that are fantastic about wriitng things outside of their world and wheelhouse, and I'm not one of them. I'm digging on "The Pacific" right now, but I could never do that, because I have no frame of reference. My friends back from the East Coast jokingly call me "Hollywood," and they assume I'm out at Hollywood parties, but I'm a domesticated guy with 3 kids. 90 percent of my life, I have 3 children, a nanny in the house, and the house is just full of people and activity. And then at 9 o'clock everyone's asleep, and I wander around the house like it's an empty amusement park, I open the cupboards, see what's there that I don't always notice. So I mention this in the writers room, and they said, 'That should be what Andy does,' only we dress it up with cowboy hats and goofy music. To me, the domesticated reality of trying to find the fun in the day to day drudgery of life is what I'm living right now. And what Courteney's living right now. That's where it comedically came from.

And has there ever been a pitch in the writers' room in this area where you've all felt, "Well, that's too dumb even to come from someone like Bobby"?

I love television, I specifically love having a dumb character on a TV show. Dumb is a word that doesn't do justice to it. But we've got Brian Van Holt, who's been great as Bobby. On "Spin City," we had the mayor. "Friends" had Joey. To find a character where you can do those jokes and yet protect him as a human being, it's so fun, but it is a constant battle every week when you're going, "Should this guy really be chasing a balloon around for 3 episodes and jump off a building?" And then we have to find a way to tie it back to reality somehow. There have been countless stories where we haven't been able to tie it back.

What the show became about is that my favorite TV involves characters who really seem to enjoy and like each other. As these actors started to gel in real life, that's been driving the storytelling.

Josh Hopkins is someone I had never thought of as funny in anything I'd ever seen him in, but here he's very lively, has the guitar, playing goofy songs. How did you know that side of him was in there, and how long did it take to bring it out?

We lucked out. I only knew Josh as a dramatic actor. I had seen him when he played a romantic interest in "Cold Case." He was like a DA. He was just charming and roguish, but wasn't doing a lot of comedy on this show. On this show, we figured he'd just be a tall, dark and handsome guy. But in the downtime, I'd find Josh to be a funny guy - unlike most handsome face jocks, he's a messed-up commitment-phobe tortured person in real life. Five weeks into production, he was playing his guitar and making up idiotic songs. I literally drove by in a golf cart and said, 'You're gong to be doing that on a show." And he said, "Really? I've never done anything like that in a job before." And I said, "All you have to do for me is promise to own it and not be embarrased by what you're doing." I think it's scary for people when you haven't done comedy a lot.

Well, you mentioned the story about the guys dancing at night to the goofy music, and when you put Josh in those old high school jeans and cranked up the Enya, he really went for it.

Right before we shot it, he went, 'Are we really doing this?' Comedy only works if everybody's a gamer.

The whole season had been more or less building towards Jules and Grayson getting together, and then you did the episode last week that a lot of us old "Scrubs" fans compared to "My Bed Banter & Beyond," and so we assumed it would end with them splitting up again - only they didn't.

I've done that before. Right or wrong, one of the things I notice, I read stuff now and then, is that some of the people who liked "Scrubs" have followed us to this show, so to be repetitive, I would take some well-deserved hits for it. It's the same battle every year. If you have a single man and a single woman and they're attractive, and if there's at all romantic chemistry in the pilot, there are lot of roads to go down. But the one we haven't gone down is where we just say, "To hell with it. If they're adults, why can't we just follow this relationship along now?" For me, it's open-ended. Courteney was cool, too She went on Twitter, people were calling them "Juleson," and she said, "It seems like more people like 'em together than don't." As long as it's funny, we'll keep them together. The trick is not writing stories about it every week. I can guarantee that when next year starts, they'll be a couple, but it won't be "What hurdle can we overcome as a couple?" There'll be some other story where they happen to be a couple in the middle of it.

Well, you did that with JD and Elliot in the final season of "Scrubs" - they got together, but then it just became a fact of life.

I enjoyed it. I enjoyed writing it because there wasn't any pressure on it. I think Courteney's very strong at playing romantic comedy moments, like when she makes him go out and get her stuff after they've had sex. I don't think you can do that the same way with "faceless, nameles, personality-less 27 year old." It's tough. When I think back to your initial questions, I think I couldn't have gotten to this point without the pilot. The pilot was about a woman re-entering the world

But it seems that shows can fall into two traps with couples: they're afraid to put them together, and then when they do, there still has to be relationship drama every episode. Sounds like you don't want to fall into either one.

We made some rules on the board: if an episode is gonna be about the couple ever, it has to be raucously funny, and a story you're telling for funny's sake. Otherwise, if there's ever a story with any depth, it will be a tip that we've decided to break them up moving forward.

And moving forward, how are you going to deal with Travis being 20 minutes away at college? That can be treated as a short distance or a long one, depending on how much you want to use him.

The guy's too good. The reason we did that story was because we were trapped into the conceit that he's a regular on the show, so people know we're not firing him. I think that, initially, we will get to see him cruising in and out, and how that affects a mom being alone for the first time, but I would be doing the show a disservice if I didn't find a way to get him back home.

And it's always odd how there's this bunch of 40somethings, then there's Laurie who's also a grown-up, and then there's this teenager hanging out with them.

I like that he's almost the adult observer of a group of grown children. I long for the day when he's old enough when he and Laurie can flirt without it being creepy. I think in real life, those two aren't that far in age, but the way they've been written, whenever we do a scene where Travis is into Laurie, that was always met with the network going, "That's inappropriate."

Yeah, he plays down and she plays up, in terms of age.

In my head, when he's television 20 and she's television 29, no one can say anything. But right now, we really brought Smith in to humanize her and make her a legitimate character. The same way Bobby is in danger of being too dumb to be believed, she's in danger of being over the top in the way we write her, so we figured we'd put her with a guy who's not a guy you'd imagine her with, and then have behave exactly the same way, to kind of validate her personality. I'm not sure how long we will do that, especially since he's a regular on the Shatner show.

And how do you choose to deal with baby Stan? There are episodes where he's around and then lots of others where Ellie and Andy are acting like they've never had a kid.

People assume that baby decisions are creative decisions, but they're production decisions. Babies can work 10 minutes a day, and it can be a three-hour process with the lights and the baby being fussy. And since we only have 21 and a half minutes to play with in the show, you have to throw the lip service to where the baby is and who the sitter is out the window. We've established that his mom sits for them, we have them with a monitor a lot, and now we've established the nanny, just so people will stop asking, "Is the baby dead?" Except when it needs to be in the story out of pure necessity, out of comedy, I don't want to see it. Your enemy in single camera comedy is time, and babies eat time. It's amazing how quickly they devour it.

Okay, now a nerd question: we've seen characters on the show watching "Scrubs," but we've also seen Coffee Bucks and Winston University. So is "Scrubs" a TV show in the "Cougar Town" universe or is Sacred Heart a real hospital in it? Could you do an episode where Jordan and Ellie are revealed to be identical twins?

I'll tell you the truth: in my head, Sacred Heart is an actual hospital, and Coffee Bucks is an actual chain. The "Scrubs" on a TV came out as a nice gesture on the post-production team, they needed to have something on the television they were watching. If it had been up to me, I probably wouldn't have used it. I said to (producing partner) Randall Winston, "They shouldn't be watching 'Scrubs' on TV," but he said if you don't  establish 'Scrubs' is a TV show, then if any of those actors come on the show, then I would have to do what you suggested, and I really don't want to.

Well, I have to ask: week away from the ABC upfront, is there any reason "Scrubs" fans should have hope for yet another season?

That would be the world's biggest late decision. It would truly mean that I had sold my soul to the devil. The show would be a Terminator. It can't be killed.

The tough part is, you learn stuff in television every year, for business reasons. The very reason that ABC picked up the show - they felt if you restore Zach to the show, it would have some back-end worth - to us, it was in retrospect the one thing that kept the show from having a chance. One of the things I discovered is that it's very hard to introduce and establish four new characters and a new world when you're still doing the old world. So in retrospect, I watched the work those guys did. A good sign of a TV show is it gets better and not worse. By the end of the season, the last 4-5 episodes, I was really interested. It felt like a new world. You always find what the show is, and they couldn't do that in the first few because Zach was still there, then the next few would have been Eliza Coupe and Michael Mosley, which was a couple I hadn't really seen before on TV. I wish they could have done that show. They were trying to find a way to pitch a spin-off for those two.

I think "Scrubs"' time was over, and in retrospect it never would have made financial sense to make it, but a show called "Med School" with no Zach or Sarah, and just Johnny C as a teacher and the students would be a fun show to see. Take out the voiceover, lose the fantasies and you have a good show.

Alan Sepinwall may be reached at sepinwall@hitfix.com