optimize merge_files