fix index overflow