Optimized Trick to make use of foreach instead of for.