fixes a bug when iterations is greater than 1