changed for loop to range