fix bugs of overwritting the same file