added iterate function, and passed all the tests