Improved the CSV-generating code to create one CSV per table and other tweaks