simplify for-loop
change upper bound from inclusive to exclusive