Moved csv writing