Added flush after writing data.