fixed bug in iterator solution