moved file out of foreach