Make code Groovier by using range instead of for loop