fixed export + outsourced database connection determination