fix branch idx bug