fix bug: iterator exit too late