Cleaning up output for bulk upload into database