Optimized some more foreach statements