Fix broken build by consistently using ni1 rather than ni-1 throughout the code