change for loop to make it hopefully work with IE