return correct index when there is no target