Fix problem on negative index due to integer overflow