fix result iterator implementation to avoid redundant queries