Fixed uses of wrong loop variable.