Maybe extract this into a function that returns the index?