rewrote iterate function due to pointer issue