fix writing of last coefficient