Optimized loop. speed things up a bit.

commented out code retained for readability.