Minor optimization for the for loops