Consolidate db grow/shrink code, and fix runaway expansion