David Cameron has said "gaps" in national security must be plugged as he defended plans for more secret court hearings and more internet monitoring.

It follows concerns raised by Deputy Prime Minister Nick Clegg and others about civil liberties implications.

Mr Clegg said allowing ministers, not judges, to order court proceedings to be held in secret went too far.

The prime minister said there was still time "to deal with everybody's concerns" before firming up the plans.

Proposals have been put forward to allow sensitive intelligence information to be heard in secret by a judge and "special advocates" in civil cases brought against the government.

It follows a case last year in which the government eventually settled out of court with 16 former Guantanamo Bay detainees, after the Supreme Court ruled it could not go to "closed material procedures" (allow secret evidence) in civil cases.

Final say

The deal ended the men's damages claim for which they were demanding to see secret documents detailing their detention and ill-treatment by US forces in the wake of 9/11.

Theproposed expansion of the use of secret hearingsto civil courts and inquests is intended to ensure the government can contest such cases in the future, rather than settling them to avoid sensitive information being revealed in open court.

ANALYSIS Wrangling between ministers on highly sensitive aspects of policy is now commonplace. Deputy Prime Minister Nick Clegg - keen to flag up his party's claim to be guardians of civil liberties - saw his doubts about extending the use of so-called secret trials leaked overnight. Justice Secretary Ken Clarke argues, publicly and on air, that judges will have the last word on whether civil proceedings - where secret intelligence material needs to be protected - will take place behind locked doors. And there will be no ministerial attempt to impose secrecy unless national security is at issue. However, Mr Clarke suggests the judge's role will be comparable to judicial review: in other words reviewing the process, not second guessing the decision itself. That is a potential stumbling block. And will inquests be included? There's much wrangling still to come, and thanks to the goldfish bowl politics of coalition, we'll see it unfold in the run-up to important local elections in May.

BBC security correspondent Gordon Corera said there was no doubt that the changes were also being pushed by the intelligence agencies MI5 and MI6 - partly due to concerns in the US about shared intelligence being revealed.

Justice Secretary Ken Clarke told the BBC: "The Americans have got nervous that we are going to start revealing some of their information and they have started cutting back, I am assured, on what they disclose."

But Mr Clegg has reportedly told the prime minister, ministers and security chiefs on the National Security Council that, without changes to the current proposals, his party would not back the legislation.

The Daily Mail reportedthat Mr Clegg believes it must be a judge, not ministers, who get the final say on when the powers to hold a secret hearing should be used, and argues that powers should not apply to coroners' courts.

It follows a separate row over plans to increase monitoring of phone calls, web and email use, criticised by some, including Conservative backbenchers, as "an unnecessary extension of the ability of the state to snoop on ordinary people".

In questions after a London speech on Wednesday, Mr Cameron said it was his job as prime minister to "make sure that we do everything that is necessary to keep our country safe" from serious crime and terrorist threats.

He said he believed there were "significant gaps in our defences", due to technological changes such as people making phone calls using the internet and because it sometimes was not possible to use intelligence material in court cases.

'Huge engagement'

Difficult decisions needed to be made and it was important that the "government makes progress on these vital agendas" - but it would be done in a "moderate, calm and reasonable manner".

He stressed there had already been "huge engagement" with the legal profession and civil liberties groups and added: "We are not at the end of that process yet... these are issues that we need to deal with. There is still time [before the Queen's Speech] to deal with everybody's concerns."

But he added: "Prime ministers have a responsibility for national security. We should take every step that is necessary, to keep the country safe, we shouldn't put our civil liberties at risk by doing so, but where there are gaps that need to be plugged, we need to plug those gaps."

Mr Clarke says the secret court hearings would only be used in a very small number of very sensitive cases and told the BBC he was sure he could reassure Mr Clegg. He said it would not just be up to the justice secretary to rule on what should be held behind closed doors and a judge "should be able to check that decision by a process similar to that of judicial review... the judge must have the last say."

But he said he disagreed with Mr Clegg on the issue of coroners' courts, saying that without the ability to hold private hearings, relevant security service evidence would not be heard at all.

In their report into the proposals, published on Wednesday, MPs and peers on theJoint Committee on Human Rightssaid the government had not made the case for allowing more court hearings and inquests to be held in secret.

The committee said the "inherently unfair" plan was based on "spurious assertions" about the risk of material being made public and was a "radical departure from long-standing traditions of open justice".

'Just woken up to problem'

Shami Chakrabarti, director of human rights campaign group Liberty, told the BBC that it would change procedures for people bringing a civil claim against public bodies.

"It's not just the public and the press that would be cleared out of the courtroom, the claimant and their lawyers will be shut out as well. It would allow the authorities, whether it's the security agencies or the police or whoever, to have a private chat with the judge, and I'm afraid that's not justice at all."

She added that powers would not be limited to national security matters - the green paper says the procedure could be triggered by the secretary of state deciding "that certain relevant sensitive material would cause damage to the public interest if openly disclosed".

Labour leader Ed Miliband said while there was an "issue that has to be addressed" about intelligence from foreign governments, the current proposals went too far.

"I think we need to look at a solution that actually meets the problem that exists and doesn't go far far wider, which is the problem with the government's proposals."

He said Mr Clegg had only just "woken up to the problem", adding: "I hope the government changes course and thinks again."

Closed hearings involving special advocates are already used in a number of cases, such as deportations on national security grounds and challenges to counter-terrorism control orders. But when the government tried to use it in the damages claim brought by former Guantanamo Bay detainees, the Supreme Court said it had no power to do so in civil claims for damages.