changed foreach to for loop so it works on i.e.