added file flushing