fix stackoverflow index bug