fixed wrong write to csv