Optimize requires into foreach loop