fix index mis-calculated bug