Fix iterator ref bug