Better implementation of export to csv