added counter that checks occurence of reduce function and inserts header row if first occurence
added counter that checks occurence of reduce function and inserts header row if first occurence