Avoiding reading the same file N times