Extract indexing to separate routine.