fix a bug in Writer
fix a bug in Flush()