Merge code in from #2395
Deconflicts and lands #2395, a rework of persistence