Fixing bug where all database tables were outputted into single table file