Adding an apply index function