WATCH: President Obama visits the Daily Show

Between a campaign event in New Hampshire and a roast at the Alfred E. Smith Memorial dinner, President Barack Obama stopped by for his sixth visit to The Daily Show with Jon Stewart, treating an enthusiastic studio audience to a substantive discussion on many of the issues at stake in the remaining days of the campaign.

The conversation, which extended past the show's regular half-hour format and went on for 17 minutes, ranged from the economy to Libya, Obama's Republican opponent Mitt Romney and the president's case for a second term.

Obama's debate performance in Denver made low-hanging fruit for Stewart, who missed no opportunity to skewer the president. Pulling out photos of Obama and first lady Michelle Obama after each of the first two debates, Stewart playfully asked the president if he could identify which was which.

When asked to make a positive case for a second term (as opposed to a negative case against a Romney presidency), proudly listed 'promises kept,' particularly on national security and foreign policy.

"I do think that part of the presidents job is not only moving forward on things that will work, but also preventing things that won't work," he said.

A promise not to restrict gay and lesbian rights in the Constitution got a big cheer from Stewart's live audience, which tends to skew liberal.

"When you think about it, it's--it is two sides of the same coin," Obama continued. "The question is, what kind of vision do you have for this country? What I have been fighting for for the past four years, what I intend to fight for for the next four years, is an economy is based on the free market, rewards individual initiative, rewards people that are starting a business, taking risks, but also says that there's some things that we do better together.

"There are a whole bunch of things we can do right now that will make the recovery even stronger. When you look at what we did with the auto industry, that's not the only industry where manufacturing can take root back here in the United States again."

When Obama delivered his standard line about asking "millionaires and billionaires" pay a little more to preserve funding in education, Stewart interrupted.

"Wait, I'm sorry, this is the first I'm hearing of this," he said, leaning in. "What is that about millionaires? What are you doing to us?"

Wagging his finger in the president's face, he stopped any further explanation. "No, I'm going to throw to commercial and you and I are going to have a conversation."

"Sometimes you've got to make some tough calls, but you can do that in a way that's consistent with international law and American law."

When talking about Bush and warrantless wiretapping, he said, "they're not real sexy issue."

Stewart got a good laugh line: "You don't know what I find sexy."

"Let me put it this way: I saw you flash that "[Fifty] Shades of Gray" thing, so I know what you've been reading. But we're not going to go there. I'm still the president."

The exchange the got the most attention--and even some criticism from Republicans over semantics, was unsurprisingly over Libya.

"Jon, the truth is is that information comes in, folks put it out throughout the process, people say, it's still incomplete. What I was always clear about was we're going to do an investigation and figure out exactly what happened."

Stewart asked about improving communication between departments and between the government and the public: "I would say, even you would admit, It was not the optimal response, at least to the American people, as far as us all being on the same page."

It was the president's repetition of "optimal" that fielded criticism from Sen. John McCain and other prominent Republicans.

"Here's what I'll say. When four Americans get killed, it's not optimal, and we're going to fix it. All of it. And what happens during the course of a presidency is that the government is a big operation. At any given time something screws up. And you make sure that you find out what's broken and you fix it. Whatever else I have done throughout the course of my presidency, the one thing that I have been absolutely clear about is America's security comes first, and the American people need to know exactly how I make decisions when it comes to war, peace, national security and protecting Americans, and they will continue to get that over the next four years of my presidency."

United Press International is a leading provider of news, photos and information to millions of readers around the globe via UPI.com and its licensing services.

With a history of reliable reporting dating back to 1907, today’s UPI is a credible source for the most important stories of the day, continually updated - a one-stop site for U.S. and world news, as well as entertainment, trends, science, health and stunning photography. UPI also provides insightful reports on key topics of geopolitical importance, including energy and security.

A Spanish version of the site reaches millions of readers in Latin America and beyond.

UPI was founded in 1907 by E.W. Scripps as the United Press (UP). It became known as UPI when after a merger with the International News Service in 1958, which was founded in 1909 by William Randolph Hearst. Today, UPI is owned by News World Communications.