fixing bug with writefile