Moved ivs out of for loop