Grand refactoring of persistence.ts. Clearer, it seems.