handle duplicate files and another bug fix