updated csv handling code