Better iterator implementation