Anyone who counts the Palace of Westminster as their place of work is filled with an overwhelming sense of sadness over the lives lost on Wednesday. But, if I am completely honest, laced with that deep sorrow is a tiny sense of something very like relief, at least in one narrow respect: that the attack, and the misery it unleashed, wasn’t even worse.

For Keith Palmer, the policeman who, day in day out, guarded me and my colleagues – and I speak as a former officer of the Metropolitan police – there is no relief; nor for his poor wife, family and friends. Nor for other innocent victims and their families. Their loss is absolute, overwhelming, unimaginable. But there could, easily, have been even greater loss of life, and with it even greater physical pain and emotional carnage.

As a Liberal Democrat peer, now the party’s home affairs spokesperson, I guess it is my job to tear lumps out of a Conservative government for which I have little sympathy. But not after this. Security is graver than party politics. So I write simply in the spirit of improving security. That security must be balanced with an obligation to keep parliament open to the people. We shouldn’t turn Westminster into Fort Knox, even if such a thing were possible. But we can improve security, for politicians, staff and, crucially, police on the frontline.

Those officers are not armed. Armed support is a distance away. No one wants an ostentatious display of force, which would only increase that sense of alienation many feel about “Westminster”. But this attack shows, alas, that armed officers should be directly behind that frontline. Otherwise lives will be lost that could be saved. In this attack, I gather, it was only because a minister’s armed close protection officer happened to be close by that the assailant was stopped.

While millions are spent on surveillance powers and the security services, over the past six years £1bn has been cut from the Metropolitan police budget. That’s huge. This suspect was known to police and the security services. Liberal Democrats are traditionally the most hardline in defending liberty, but we support the monitoring of communication of those suspected of terrorism, with appropriate safeguards. But this needs to be focused on suspects, not everyone, and the danger of treating all citizens as suspects is that real threats slip through.

Those who are not known or who are not current suspects may get through to a high-profile target, as on this occasion. So police need to be in place on the ground – not just armed officers at Westminster, but armed response units throughout the UK. Meanwhile, we need proper resources for community policing to pick up intelligence on those being lured into terrorism.

Ultimately, communities defeat terrorism, not police and security services given – or perhaps burdened with – ever more draconian powers. Communities spot the tell-tale changes in behaviour. Trust and confidence in the relevant agencies are essential. The government’s Prevent strategy – supposedly targeting radicalised groups, but in practice stigmatising children as young as nine – is discredited because it causes resentment and drives a wedge between communities. Instead, we need to positively engage so that the security services target resources more accurately on the most dangerous, while simultaneously winning the trust of their communities.

Terrorists striking in Europe in recent months were in several cases known to security services, so the issue is with operational capacity, not identifying suspects. We need intelligent, directed surveillance, not all-embracing surveillance. After previous terrorist attacks, home secretaries typically have appealed for greater powers and accuse liberals of being “soft on terror”. The result is a political arms race to increase state might, rarely with evidence that this will make the public safer.

Instead, we should instigate the tangible changes that are shown to work, such as increasing police budgets and ensuring there are armed officers close to likely targets. Apologies for being “so Lib Dem”– as the anti-hard Brexit party – but if we avoid a Brexit that will cost the public finances £100bn, we could afford better security, while also working closely with our friends across the Channel through the pooling of intelligence and the European arrest warrant. I struggle to see how you can have a hard Brexit and safer streets.

The government’s plan to collect and store all our web histories for a year is expensive, ineffective and disproportionate. The creation and maintenance of this system is likely to cost over £1bn, money that could be better spent restoring police numbers in our community.

Whether it is working with communities or other intelligence agencies, we should work together. Terrorists want division, and we should not be so foolish as to give it to them. Let us remain open, tolerant and united.