Do separate phases 4 and 6 for each file, not once for all files.