Store database fixes

Fixes a pile of database annoyances and strangeness.