Restructured the for loop to the usual format