Fix the algorithm to find and compare files between two references