add flush after each write when needed