Changes for saving file to CSV + Alex's modifications