DocCode: repair massively wrong save code and clean up dirty db
I guess I never tested this stuff.