DB export, document code, and fix loop