Fix incorrect index bug