use range instead of for loop