Added functionality to create header row when writing a query