replaced for in loops with normal enumerating loops to fix #1803