The SNP won the election in Scotland and were it not for the tsunami of 2015 pundits would be hailing an historic landmark victory - 35 seats out of 59 ain’t bad, especially on 37% of the vote. But this result is a distortion of the first past the post system.

Turnout was down. A quarter of a million fewer people voted than in 2015. Yet we mislaid nearly half a million votes. A third. Our vote share fell by a quarter and we lost a third of our seats. More to the point, we won a swathe of others with wafer thin majorities and most of the seats we won should now be regarded as marginal. Two years ago we had more than 50% of the votes in 35 seats – today not one.

These results are a wake-up call for the SNP. We need to understand why people who voted for us before decided not to this time. And we need to get them back. This requires a radical re-think and we do not have a lot of time to do it.

Detailed research into who voted for whom will be needed before we can say for certain why things happened. But it seems clear that three main factors were in play: Brexit, Indyref and Corbyn. These inter-relate and some are more relevant in some parts of the country than others.

The Tory obsession with Indyref2 paid off. Their main achievement was to galvanise the pro-union vote around them. In seats like mine there was a small but significant shift from Labour to Tory, mainly older Labour voters for whom the union was more important than social or economic reform. They were also influenced by the media’s perception of Corbyn – and not in a good way. Some switched allegiance to the Tories – others were softened up to vote tactically. This process was undoubtedly helped by the call from the Scottish Labour leadership to vote for anyone but the SNP, implicitly telling Labour voters it was okay to lend their vote to the Tories. Many did exactly that in the likes of Ayr, Stirling and Aberdeen South. Had those Labour voters not heeded their leaders Theresa May would not have a majority even with the DUP.

It was never part of Tory strategy to switch people from SNP to them - the main objective was to garner more of the anti-independence majority. That said, their campaign also had some effect on our own support by challenging the legitimacy of our claim for a second referendum. I doubt many voted Tory as a result, but a lot seem to have stayed at home. Either way our vote went down.

So what do we do about Indyref? First off, we are right to say that if there is a dramatic change in circumstance people should have the right to re-visit the decision they made in 2014. And we do indeed have a mandate for that position from the 2016 Scottish general election.

Brexit is most definitely a change in circumstance. It has two consequences. One, it changes the UK. Two, Scotland didn’t vote for it so it begs the question of whether we will be forced into something against our will. In an attempt to respect the Scottish people’s expressed opinion of 2014 and 2016, the Scottish government, which believed in both independence and the EU, proposed a compromise involving neither. Instead it argued for differential post-Brexit arrangements for Scotland which would allow us to have a different relationship with other European nations whilst still part of the UK.

The rejection by the British government of the Scottish government’s framework document meant we were right to insist upon another referendum at the end of the process. Our argument was that whatever came out of Brexit, the refusal to stay in the single market or consider differential arrangements for Scotland meant that the UK would have changed so much that people should get a choice again. It also meant a refusal to listen to the wishes of people in Scotland.

However, the campaign by the Tories to characterise this as a refusal to accept the 2014 result worked and our attempts to explain the timetable for indyref2 meant the whole debate became one of process rather than principle. We ended up arguing about the merits of a referendum rather than the merits of independence. It’s clear also that many of our own supporters didn’t get or didn’t buy the argument – mainly because Brexit hasn’t happened and no-one could say for sure how the UK had changed.

The election result changes everything. Now the single market is back on the table, now we can argue for separate Scottish arrangements, now there is prospect of repatriation of powers from Brussels direct to Holyrood to a maximal rather than minimal extent. There is a point to fighting for all of this - and some of it we will win. This means that the outcome of Brexit may be a lot different than the one we were heading for in March. Amidst the current chaos in Westminster it seems certain that a hard Brexit is now off the table, and the possibility of bespoke solutions for nations and regions is growing.

It follows, therefore, that it is now an option to wait until the Brexit negotiations conclude before forming a view on whether the extent of change justifies a second independence referendum as a result. This would mean that whilst a second referendum remains an option, the timetable gets parked.

Whether we adopt that option in large part depends on what attitude the British government now takes. If there is a positive response from the Prime Minister to Nicola Surgeon’s request for an all-party, all-nation approach to the Brexit negotiations then there seems merit in exhausting that process first. If, however, May maintains a blinkered and belligerent stance then the stand-off continues – only with the odds more in our favour than they were in March. In the meantime we should be working up the case for self-government with renewed vigour and preparing a prospectus for an independence campaign that is not conditional on Brexit.

Brexit itself is the second big factor. Some SNP supporters like Brexit – they voted for it. They believe that membership of the EU is incompatible with independence. They’re wrong, but that doesn’t mean the perception isn’t real. In some areas of the country where the Brexit vote was strongest this led to a straight switch from SNP to Tory in significant numbers. Elsewhere it is more likely that the antipathy of SNP supporters to the party’s pro-EU position simply meant they stayed at home.

This would in part explain the big fall in overall turnout which occurred despite all the evidence pointing to a large increase in the youth vote. We need to do more to win back these voters, explaining that whist we seek membership of the EU for an independent Scotland it will be on our terms, and we want to negotiate a deal for Scotland that is better that the one we had in UK. We might even want to consider a further referendum on that at the end of the process – and an EFTA/EEA option as either a halfway house or interim step.

But Brexit and Indyref2 are dwarfed by the main factor at play in this election: Jeremy Corbyn and the Labour manifesto. This is the main reason why we lost seats to Labour, and why we now have many SNP/Labour marginals. I really didn’t see this coming. Throughout the campaign there were people I canvassed who were previously identified as SNP who said they were attracted to what Corbyn was saying. But it was easy to dismiss by saying that he wouldn’t win and, besides, we supported all the good ideas anyway. However, that argument was holed beneath the waterline when the polls narrowed in the final ten days and the media began to talk without the attendant ridicule of the possibility of Corbyn being PM.

True, much of the stuff in the Labour manifesto had already been implemented by the SNP Scottish government. True, the SNP manifesto had a harder line of combatting austerity. True, Scottish Labour didn’t like Corbyn anyway. None of that mattered. The psychology took over.

Suddenly, it seemed possible to turn the world upside down, give the establishment one in the eye. Suddenly, there was an insurgency gaining momentum, fuelled by a highly effective social media campaign. Our voters like insurgency. They are intrinsically anti-establishment. They were seduced. They wanted to be part of it. I know a number of people who voted Yes in 2014, SNP in 2015 (and 2016) and who voted Labour last week. They haven’t necessarily changed their mind on independence, but they see no incompatibility between supporting a left party in UK elections and voting for independence in Scotland.

Certainly, in seats like mine, what looked like a net swing from SNP to Tory was in fact a swing from Labour to Tory in the unionist right of centre which was masked by a bigger swing from SNP to Labour on the pro-Indy left of centre.

This Corbyn surge happened in spite of the Scottish Labour leadership and has left them cold. Two great ironies present: firstly, the unintended consequence is that by voting Labour in Scotland people have sent to Westminster people who will be considerably less helpful to Corbyn than the SNP incumbents would have been, but that will be difficult to expose because Labour lost and are not going to be in a position to deliver their manifesto. Besides, they are all Corbynites now, everyone loves success. Ask Peter Mandelson.

The second irony is that with the leaching of unionist support to the Tories and the gaining of left wing pro-Indy voters, Labour support is now more pro- independence than ever. - and this as the leadership couldn’t be more against. This disconnect will make it difficult for Scottish Labour to capitalise on the result organisationally.

Irony number three is that although in Scotland the SNP was being attacked by Labour and Tories for being too radical, for pushing too hard, in reality we lost most votes from people who felt Corbyn was more radical than us - and yet we are the real insurgents, the real force for change. We need to reclaim that mantle and do it quickly. By allowing the argument to become about the performance of the Scottish government - whether or not we are doing the day job - we are in danger of being seen as the establishment. Of course competence is the bedrock on which we have to build aspiration. But day-jobs are boring; doing them is boring. They do not fire the imagination or stir the heart.

The SNP needs a series of initiatives to give it back a radical cutting edge. We need to switch the debate from performance to policy. And we need to explain better what we are being prevented from doing. We rightly point out that we have achieved much in the Scottish government but it is vital that people know what we cannot do because of the constraints upon us.

There will, of course, always be some people on the right of the political spectrum who support independence. But not many. A majority for independence can only be built by convincing people that it is a means to changing their world for the better, by aligning the cause of democratic constitutional change with the case for progressive social and economic reform. We were on that course but the election was undoubtedly a setback. The social democratic majority in Scotland is now fractured and we need to put it back together.

The ranks of the independence campaign swelled in recent years as masses of people, especially the young, saw it as a better route to social change than any UK option. Corbyn or no Corbyn that is still unquestionably true and that is the central argument we need to get back to.