Fix bug: visitor to IndexQueue may have side effects on first/second.