Warning: spoilers for the Season 3 finale of Silicon Valley are ahead.

The end of Silicon Valley's third season wasn't a shocker or big cliffhanger, but the world of Richard Hendricks (Thomas Middleditch) and his compression company Pied Piper changed forever. When news of the fake users Jared (Zach Woods) bought came to light, Reviga's CEO Laurie Bream (Suzanne Cryer) decided to sell. When it looked like Richard's archenemy, Hooli CEO Gavin Belson (Matt Ross) was going to buy it, the suddenly re-flush pair of Erlich Bachman (T.J. Miller) and Nelson "Big Head" Bighetti (Josh Brenner) stepped in and out-bid Gavin for the company's remains.

Also, the company will pivot to become a video-chat company, after the app Dinesh (Kumail Nanjiani) created as a way flirt with female developers proves to be more popular than Richard's amazing, but inscrutable, compression platform. Alec Berg, who is co-showrunner of Silicon Valley, talked to TV Insider about the season and how much longer he and co-showrunner Mike Judge think they can continue keeping Pied Piper on the verge of success.

RELATED: Silicon Valley's Kumail Nanjiani on Dinesh's Fashion 'Don't' and the Season Finale

The last three episodes were very twisty, but Pied Piper ended back up in Erlich's house at the end of the season, with Erlich and Big Head as the owners. Was that the goal?

Yeah. Look, this is the fundamental conceit of the show. We've always thought of it like the Bad News Bears or Animal House, that this is a group of outsiders. I think the fundamental question that the show is seeking to answer is, "Can Richard, in particular, but can these guys win the game without losing their souls?" Them being outsiders, I think once you get to the point where they're insiders, I think the show's over. I'm not sure that these guys can ever really win and be wealthy and fulfilled and have success beyond their wildest dreams and also have done it correctly. The show is definitively over when that happens.

The challenge with the show is how many and, like you said, twists and turns? How many interesting, different ways can these guys struggle before people just get tired of them struggling and not winning? You know?

It does seem like the struggles are true to life.

A hundred percent. No, I think that's part of ... I think that's a very much by design. We're not out there inventing like, "Oh here's a fantastical way that no one in the real world has ever failed. Let's have them do that." That's the beauty of the research is that there are hundreds and hundreds and hundreds of companies that fail. They fail in all sorts of fantastic, interesting, compelling ways.

The whole idea of putting out a product that's miraculous in the way it operates, but you can't explain it to the general public rings completely true.

The story of Twitter is a story we draw on a lot. At one point, Evan Williams had gotten a company called Odeo funded. They were a podcasting company. Then iTunes added podcasts. They were in the midst of developing this platform and they said, "We're dead. iTunes just added podcasts. We're never going to succeed."

The engineers at the company had been playing with this little, in house idle waste of time that they were calling Twitter. Evan Williams went to the investors and he said, "Hey, we can keep building this Odeo thing, but it's never going to work or we can keep your money and keep developing this thing we call Twitter." They said, "What is it?" He tried to explain it to them and they said, "We have no idea what they're talking about. We don't know what that is. We're not interested in that." Evan Williams paid them $5 million out of his own pocket to buy the rights to Twitter back from them.

That's a very real thing that they were developing something and nobody knew. That's the thing. When you innovate to the point where something is just it's not a new version of something old, it's a new thing, I think a lot of times the biggest challenge is just the indifference or the anxiety of the consumer.

Is there going to be an issue next year of Richard having to deal with the fact that the company is now pivoting towards this video chat app, and it won't be about the compression platform itself?

That remains to be seen. That's the tremendously difficult job of writing next season. I wish I could tell you we had it solved, but we sort of don't. I think the process of this show has been continuously writing ourselves into a corner at the end of a season and then taking a breath and going, "Okay, how do we dig ourselves out of this one" and dig ourselves into an even bigger hole.

That's the challenge of this show. It is this thing of you constantly want to be rewarding your characters for their faith and their hard work and their expertise and their genius but, if we reward them too much, then they just become idle. The Bad News Bears can only win the championship so many times before they're just the Bears.

Is there supposed to be a natural state of things where Bachman can't be in an inferior position to Richard, for instance, because he's such a pompous ass that he needs to be somehow in a more powerful position?

We're in a position now where, barring renegotiating the capitalization of the company which I'm sure will be a topic, Erlich owns 50% of the company and Richard owns none.

Is Bachman a better character when he can be pompous for a reason?

Look, I think he has a lot of clubs in his bag. We learned early on, Season 1, the first few episodes we wrote, he was this constant thorn in Richard's side. He didn't really become an interesting three-dimensional character until show 4 of Season 1, where Richard needed him to go into this meeting with Peter Gregory and needed him to sell Peter Gregory on the big picture dream of the company and what it could become. Richard just didn't have the social skills to paint that picture.

Erlich finally was a bull in the china shop, but for Richard's good as opposed to just constantly hamstringing him. That was a really important episode for us because I think a lot of people were starting to feel like, "Well Erlich's just this ass who keeps screwing things up. Why do I want to root for that guy?" Then when you see that, "Oh he's an ass, but sometimes he's a blowhard for good and sometimes the fantastic yarns that he spins actually work. Sometimes he's a plow. Sometimes he runs over Richard but, sometimes Richard can run behind the plow and the plow works in Richard's favor."

Like his miraculous series of events to get the funding in the finale?

Exactly. He took the little uptick and spun it into Series B financing. That's his genius. It's sometimes he's a bulls--t artist in an effective way, and he can actually do tremendous good for the company.

How much do you have T.J. improvise because some of the stuff that comes out of Erlich's mouth seems very so out of left field sometimes?

He's a tremendously skilled improviser. All of the guys are skilled at improvising, but they're also really, really good at knowing where improvising is going to add to the value of the material and where it's just going to get in the way or it's just going to slow things down. They understand how writing works because they're all writers.

What's an example of something that, especially in the last half of the season, that made it in that was just either an alt or something that they just found while doing the scene?

The stuff where T.J. is posing for the photographer. That was a scene where I think we had one line in there of like, "Don't shoot me from this angle" whatever, something or other. That's a prime example of a place where we're like, "You know what? Let's just put in something here and give it to him. He's going to come up with 20 things that are funnier in that moment." That's a prime example of one where that instance, that's not something that's driving the plot or the story. It's not something that requires tension and driving forward of anything. It's not something that requires technical accuracy. You know?

Sometimes that happens. Sometimes they're like, "Wait, do you I have to say it this way? It's really hard to say that way. What if I said it this way instead?" We've got a tech advisor on the set who says, "Well you can't say it that way because that's wrong. It just means that line is incorrect if you say it that way." That photo session is a prime example of, "We just know that everything that comes out of his mouth is going to be funnier than anything we could write, so let's turn him loose."

When Stephen Tobolowsky's character Jack introduced the box, I had a bunch of people on my Facebook feed talk about how familiar the feeling of having a new person come in and make changes was. And none of them were in IT. How tough is it to keep themes universal while keeping things accurate for the tech folks?

That's the job. That's ideally why the show has tremendous appeal. That's just the work of the writing is to do the research and to learn about all of these things that are going on in the tech business and then present them in a way where somebody who works at a bowling alley or somebody who works as a security guard or somebody who works in finance or somebody who works as an English teacher can watch the show and say, "Oh my God, that's exactly like when my boss tells me this" or "That's like when my students do this and then I tell them to do that and they blame me for it." Look, we do a lot of that. There are a lot of parallels. Both of my parents are college professors. As writers, we're finding the universality in the things that we're talking about in the tech business also.

It does seem like there's lots of fun little inside stuff there for the tech folks, though, like the little Lyft balloon butting up against the bigger Uber balloon in the intro.

There's a ton. I don't know if you've ever heard the term dog whistle, but that's a lot of them are what we call dog whistles, which is basically like if you can hear that frequency, you notice it. If you can't hear that frequency, it doesn't bother you. It doesn't even exist to you. We try not to do any jokes where if you don't understand the tech of it or you're not up to speed with that stuff, you're not included. We put little things in all over the place that, if you are familiar with the tech business, they're just added value. It constantly has to work for everybody or we've failed.

RELATED: Silicon Valley is Using Google to Publish Fake News Stories in Search Results

What's a good example of a dog whistle from the end of the season?

We do stuff like anytime you see code on a screen, it's real. Anytime you see anything on a screen, we've had meetings about it and discussions about it. We've consulted experts about it. We put a thing in the first episode this season, Dinesh and Gilfoyle (Martin Starr) are going through Richard's code base trying to see if they can figure out how he did stuff. There's a page full of code. We actually had somebody write for us a simple, I don't know the technical term for it, a simple subroutine or something where if somebody actually compiled that code and ran it, it just it printed out on the screen "Dream On A-----es." That's one where it's like a bunch of people are like, "Ah ha, we caught you." We Easter egged them.

There's a reference to Theranos. There's a reference to the word "decacorn." There are a lot of these things that ... In show 8, Mark Pincus, who's the CEO of Zynga, is talking to Laurie Bream. Then Dick Costolo, the former CEO of Twitter is talking about how somebody sold him the bad vineyard. There are a bunch of cameos of people that, if you don't know who Dick Costolo is, you're now sitting there going, "I don't understand what's happening right now. What's this scene about?" If you know who Dick Costolo is, you think it's funny that this guy's talking about buying a bad vineyard. If you don't know who he is, you still might think it's funny that a rich tech guy is annoyed that somebody sold him a bad vineyard. The fact that it's actually Dick Costolo I think, to people who know who he is, pluses that situation.

How hard is it to keep Big Head from getting too stupid to live?

That's a constant, yeah. Look, there's nothing more enjoyable than pitching Big Head is stupid jokes. The show tends to work best when it cues to reality. Mike and I are both I think acutely sensitive to ... Somebody told me what I started working with Mike, they said, "Just know this, Mike is toxically allergic to jokes. Don't ever think that you're going to be doing jokes because he just doesn't like them." Most of the comedy of our show, I like to think, is like character and dialog driven. It's not sitcomy. It's not set-up-joke, set-up-joke. There are jokes. There are laughs, but I don't think it's as sitcomy as a lot of half hour comedies are.

With Big Head, he took a settlement and squandered it. Now he's half owner of Pied Piper.

Yeah, but why is that? It's because in episode 10, off camera, Big Head realized the value of that video chat. Big Head went to Erlich and said, "Hey we need to pool our money and we need to buy the company because it's going to be worth something." He's a dummy, but he's also smart enough to be the savior of the company.

He's not the guy failing upwards?

In this case we'll see. He could have walked away with half a million dollars, but he sunk it into what potentially could be a failure of a company. Who knows? Hopefully he's a genius and hopefully he just bought a billion dollar company for $500,000.

On the Hooli side of the ledger, a lot of this season was Gavin shaking his fist going, "I'll get you Richard Hendricks!" It didn't feel like he was as integrated with everybody as he was the first two seasons. Is that difficult at this point because of the way the story's diverging?

We'll see. I'd love to find new ... Richard versus Gavin Belson I think is a fun battle. You know? When they're really going toe-to-toe and directly impacting each other's lives, I think the show's more interesting. At the same time, I'm very sensitive to plowing familiar ground. Season 2 was really about the lawsuit and Gavin jamming a stick in the spokes of Pied Piper. It's on us to find another new, interesting way that Hooli can threaten the potential success of Pied Piper.

Is it good though that he got redeemed somewhat, even in his own half evil way, at the end of the season? It didn't seem like a weak Gavin is something that would be good for the show.

No, I agree. What I really like about what we did with Gavin this year is Jack Barker essentially wanted to turn Pied Piper into this box company. The guys bristled. That was pure commerce trumping art.

In a way, Jack Barker was right because Gavin Belson took that business model and made a ton of money with it and is now more successful than he's ever been and in a stronger position with Hooli and with increased stock and compensation. He did right by the company, by doing what Jack Barker wanted to do with Pied Piper. You could make an argument that Barker's plan was cynical and whorish, but his job is to increase the value of the company. By following that business model, Gavin Belson increased the value of his company. Who's right and who's wrong?

By the way, I've worked in data centers like that and they are horribly depressing.

We had a joke in there. I don't know this is, talk about this is another one for those of you who notice. If you look at the ID badge of the guy who works down there. John? It's a photo of him from 25 years earlier. We had a joke in there and it didn't quite land because it was a tough, visual joke. All of the mole people are wearing ID badges that feature their much younger selves. If you look really closely, you can see that they're all wearing these IDs with them as young, hopeful people. We actually got all of the actors that we used, we had them bring in photos of them from 20 years ago.

There are no windows. You have this air conditioning buzzing in your ear. It's not fun.

It's like being in the world's worst casino.

What more can you do with Gilfoyle at this point? Can you peel away more layers with him?

Oh, I hope so, yeah. Yeah. I'd love to find a way for Dinesh to ... We still haven't really found Gilfoyle's kryptonite. In general, Gilfoyle is just relentlessly brutal to Dinesh and Dinesh just sadly has to take it and take it and take it. It's just that's been the funniest dynamic we've found.

I think it would be, to discover Gilfoyle's secret weakness or something that he's incredibly uptight about would be great. To give Dinesh power over him would be fantastic.

With Zach's character Jared, is his character just basically in the little reveals that he makes? Is that where you're finding the character?

It's funny. The number of those that have made it into the show, he's been doing stuff like we've had lines for him like that and also there were things last season like him speaking German in the night and even the very first time he came to the house, he said something about his uncle used to say that he looked like someone starved a virgin to death. Clearly, he's had a very difficult go of things. There was an improv he did season one somewhere that didn't make it in. He said something about, "My best friend Gloria's granddaughter." Just the idea that his best friend is a grandmother just really made us laugh.

He's been throwing little things like that and "I can use some of the money from my settlement with California Child Protective Services," like all these little things where you just go, "Wait. What?" That, to me, is the true joy of Jared is just getting these little peeks into the box of horrors and him saying that he had an imaginary friend when he was a child. He was imaginary friends with Harriet Tubman. They would sit in his room plotting their escape, which of course implies that there was a room he was being held in that he had to escape. That guy is so ... He is the world's greatest improviser. He is a monster, monster improviser.

He can just do that blank faced thing and say the funniest things coming out. It's amazing because it has that much more of an impact.

He's also the thing that he does that is incredible to watch is the way he plays devotion and just belief in Richard and the mission. You saw in episode 10 when Richard is going off to trade on this falsified information, just the level of sadness because his idol has decided to go to the dark side. It's crushing. His commitment to just the dream, in the face of all evidence to the contrary, is really fun to watch.

With Monica (Amanda Crew) saying at the end, "Well I think Laurie's going to fire me anyway, so I'm looking for a job." That sets things up that she might interact with the guys more than she did this season?

Maybe, maybe. Again, I'd love to say that this was all in aid of a plan that we had cooked up that we were going to cue to. A lot of it is we're just playing the cards that we've dealt ourselves.

I think we do have to find a way to keep Hooli in the show and keep them relevant and formidable and troubling. I do think we have to find a way to keep Reviga in the show and be both helpful and hurtful. It's tricky. It's like the bands releasing albums. You need to grow creatively each time but, if you change too much, then you alienate the base. I think that's the challenge that lies ahead of us is how do we keep the show the show, but also keep changing and growing and progressing so that we're plowing new territory?

Any thought of revisiting Monica and Richard together because that was explored in Season 1?

Yeah, we played with that. We hinted at that at the end of season one. It was one of those things where I think it was just a lot less satisfying once we saw it on the screen. Look, never say never, but ...

When Chris Evan Welch (who played Reviga's original visionary Peter Gregory) passed away, how tough was it to regroup and say, "We need Reviga in there, but we need a presence that's going to be at least somewhat close to what he brought to that role?"

Look that was, without a doubt, the single hardest thing I've ever had to do as a writer was ... He died when we were shooting shows 5 and 6 of 8 the first season. There were 3 full shows of story for him. I had to go through those scripts and delete those scenes. A couple of them, we had had table reads for. He had read these scenes at the table and, seeing what he did with them. We had read the last two shows at the table before he died. There was a big confrontation between him and Gavin that was just awesome. Just seeing how much glee he took in sticking it to Gavin.

You just saw this other layer of, "Oh my God, he seems like this hapless, clueless guy, but he's f--king ruthless and brutal toward Gavin." It was so much fun to see the colors. He would find things that he made you look like a brilliant writer because of the nuances and the colors that he found that you didn't even know were there. Losing him was just, in addition to all of the personal horror of a guy with young children who was that much of an amazing spirit and that brilliant a performer, of course all of the human stuff was just unbearable to see. In addition to that, losing that palette that we didn't have that character to play with anymore.

How tough was it to create Laurie's character?

Brutal, really hard. Really, really, really hard. There were a couple of incarnations that we wrote a version and we tried to cast that version. It just wasn't working. It was because it wasn't written right. There was nobody coming in that was perfect. Sometimes when you're bringing in 50 talented people and nobody is right, it's not because those 50 talented people aren't doing the work. It's because you haven't given them something that's playing right.

We had to press pause and really agonize over the character and reconceive it. We went through a couple of different iterations of this new Laurie Bream character. We finally ended up with a version that we were really happy with. Suzanne came in and owned it.

Making her a robotic type of character, does that make her different enough from than Peter?

Well the difference, I think the principle difference on the one hand it's easy to say, "Oh Peter Gregory was on the spectrum and Laurie's on the spectrum so they're the same." I think the huge difference is that Peter Gregory was somebody that could read into human behavior and could see the future because he understands how humans work. He understood human nature. He could see nine steps ahead. We did that thing where he suddenly discovered cicadas and the phases of sesame seeds and Burger King. He made $68 million. That's not something Laurie would ever be capable of. In conceit, Laurie was just somebody who was just brutally numbers-driven.

That was through research that there are a lot of people who work at VC firms who work, particularly in healthcare, who are very good at figuring out the dollar cost of very complex systems, but they don't really take humanity into consideration at all. That, in its conception, was sort of what we wanted to do with Laurie. This is somebody who's just brutally numbers-driven and just doesn't I understand how, on the surface, they seem very similar, but I do feel like at least the intention was that Laurie was a radically different mind.

Like taking Erlich's and Big Head's bid for Pied Piper because it was $1 more than Gavin's bid.

That's exactly right. That's exactly who she is. She's very good at things like that because she doesn't let emotion get in the way of making ... She's much more computer-like in that sense.

How much longer do you guys think you can go with the show?

That's a really good question. I don't know. It feels to me like we're somewhere in the middle. I'm not sure. My guess is, at the end of this season, we'll probably have a pretty good sense of how much more life the show has left in it.

A lot of the issue is how much more can Richard and the gang be kicked without it seeming like they're just completely hapless.

Exactly, exactly. Also how do we want the show to end? What's the end game of this series? It's funny. Just now in the last week or two, I've started to kind of tiptoe around that conversation when we're talking about the show of just like we've hired a couple new writers this year. Their questions were like, "So how does the show end?" It's interesting.

I did a panel last year that Matthew Weiner, who did Mad Men, was on. He was just talking about how when they made the decision to end the show, I think they got picked up for 36 more episodes. He said the math of writing the show turned upside down where it's just like when you start a show, you're like, "Where could it go? It could go here. It could go here. It could go here." Then, at a certain point when you turn for home, you start to think, "Okay what's the end and, backing up from that, what are all of the gates we need to ski through to get to that end?" You start thinking about the show in a totally different way when you're writing it. It's like what do we need to do to set that up as opposed to, "What if we went over here or what if we went over here?"

Every year you like being in that position though of, "We just wrote ourselves into this corner?"

I don't like being in that position. Obviously if I had 4 more years of seasons worked out already, that I'd love to be in that position. That would be vastly preferable. No I mean when I worked at Curb the whole philosophy was, "Just leave it all on the field. Don't save anything. If you have a good story, put it in. Don't keep any dry powder. Burn it all. Burn it all. Burn it all. Then figure out next season next season."

Because you don't want to have stories in hand and then get cancelled?

Yeah but it's also more about if you have a good story, you have to put it in the show because we don't have a lot of ... It's not like, "Oh here are 14 great episodes. Which 10 should we air this year?" It's like we're killing ourselves every year to do 10. If we have something that works as a story that we like, it's going in.