added iterative way of traversing