Eliminate unnecessary code, write correct csv file