Debugged code for adding 'per query' info to csv.