changed query to iterator