rewrite with csv handling