refactor export to csv