Replacing forEach with for loop to support older browsers.