fixed file flushing