Added a nextIndex to onLeave callback