What next for SNP after member numbers meltdown?
The SNP leadership contest has been gripped by a row over membership figures which has seen the party's top spin doctor and its chief executive resign.
What is going on within Scotland's dominant political party, and what does it mean for the race to replace Nicola Sturgeon?
How did this row begin?
The three candidates to replace Ms Sturgeon as SNP leader and first minister - Humza Yousaf, Kate Forbes and Ash Regan - started out with relatively little information to campaign with.
In some other parties, leadership candidates are given the chance to canvass members directly. But in the SNP's system, they were not even told how many members there were.
The row began when The Mail on Sunday had suggested that only 78,000 names had been given to the company running the ballot, Mi-Voice. This was sharply down on the previously reported SNP membership, which was in six figures.
Ms Forbes and Ms Regan requested further details in an open letter to Peter Murrell, the party's chief executive - who also happens to be Ms Sturgeon's husband.
The candidates were annoyed by the fact they had asked for clarification from party HQ several times, and had not received a response.
A statement from Forbes campaign manager Michelle Thomson ratcheted things up further, by suggesting the party appoint an independent auditor of the vote.
She hinted at some concerns of impropriety, without going into specific details.
This sparked a furious response nonetheless, with one SNP MP calling it "Trumpian nonsense" and "fake news", and party president Mike Russell saying staff had been abused by individuals who "damage our cause and aid our enemies".
Mr Yousaf's campaign backed the release of the figures, but said members would be upset by any suggestion the vote was not valid.
Meanwhile, opposing parties were delighted, with Labour leader Anas Sarwar joking about a "saltire-waving Stop the Steal rally" outside Holyrood and leader of the House of Commons Penny Mordaunt weighing in to call the row an "extraordinary occurrence".
What was the SNP's response?
The SNP's immediate stance was one of bafflement.
Ms Sturgeon told reporters she wasn't sure what the row was all about, saying she was "not clear what the specific allegations about the process are".
National Secretary Lorna Finn noted that the same electoral system had been used for a series of deputy leader elections, and told the candidates that "I can assure you that I am satisfied as to the integrity of the ballot".
However, the party did agree to reveal the size of the membership, having planned to do so at the end of the contest anyway.
They hoped that would put the row to bed - but it only lit the touchpaper on an even bigger dispute.
What are the numbers, then?
The SNP's year-end membership figures are normally reported annually in its accounts. The most recent number was 104,000 at the end of 2021.
The candidates were informed that the figure had fallen to just over 72,000 - a decline of 32,000 in just over a year.
This was fresh material for the SNP's opponents to crow over, and also throws fresh light on Ms Sturgeon's decision to walk away - and, perhaps, why Mr Murrell had to loan the party more than £100,000 in 2021.
Ms Forbes and Ms Regan seemed relatively content to take the win and use this as a campaigning point - both saying that it made the case for a change of direction.
But it was swiftly flagged up that the party had explicitly denied a story about the membership having fallen back in February.
After the Sunday Mail reported that numbers were down by 30,000, the party said the figure was "not just wrong, it's wrong by about 30,000".
Spin doctor Murray Foote - a former newspaper editor who actually oversaw the Sunday Mail before he moved to the SNP - had agreed to put out the response, and added his own tweet that the story was "drivel".
It now turns out to have been bang on, and Mr Foote promptly resigned.
Why didn't that settle things?
Mr Foote did not work directly for SNP HQ; he was employed by the party's MSP group at Holyrood. The distinction is an important one, because it meant he relied on others to provide him with the figures.
So his resignation could not be the end of the story. It only raised further questions.
And it was Mr Murrell who took ultimate responsibility, accepting on Saturday that the response to the Sunday Mail had been misleading.
He said he had been planning to step down after over 20 years as chief executive anyway - and many had expected that, given his wife's departure.
But he was also expected to face a vote of no confidence from the SNP's ruling body on Saturday, and his enforced departure has added to the sense of a party machine in meltdown.
What does all of this mean for the SNP?
Mr Murrell leaving would be a big story in itself. He has run the SNP since 1999, through the whole devolution era.
In that time he has turned the party into a far slicker operation, and has presided over a string of election victories.
He is probably only the first one exiting the door at HQ. Whoever takes over the leadership is likely to clean house.
And with Ms Sturgeon and her deputy John Swinney heading to the back benches with 50 years of parliamentary experience between them, the SNP is going through a hard reset.
Whoever takes the reins may have to rebuild the party machine from scratch.
Could it affect the leadership contest?
The row over membership figures was the latest in a string of unforced errors from SNP HQ during the contest.
It started with the attempt to hold hustings behind closed doors - another avoidable dispute which resulted in a predictable u-turn.
The process is unlikely to be derailed entirely, for all that Ms Forbes and Ms Regan have raised complaints about various elements of it.
The question is whether the ongoing sense of chaos makes the case for change at the top of the party, as they hope.
The drop in membership might suggest that those disgruntled with the direction of the SNP - be it over independence strategy or gender reform - have quit, leaving behind those who are more satisfied with the status quo.
So "continuity candidate" Humza Yousaf might seemto be in a strong position, especially having secured the backing of influential figures such as Mr Swinney.
But polls suggest that many SNP voters were still undecided at the point voting began, with more than enough "don't know" responses to make a big difference.
There could easily still be a large group of members waiting to cast their ballot, who are watching this ongoing bin-fire with horror.
It all means the outcome of the contest still feels totally up in the air, with barely a week to go until one of the candidates will be crowned SNP leader and Scotland's next first minister.