fix bug in writting csv result