better flow control for table.csv
made sql variable private, removed unused global
More interaction
More interaction