bug in writing csv fixed