Refactor file loop to use a loop instead of each to allow for target array modification later on