Fixed concurrency and file flushing issues.