Fix up index out of bound issue