Move offset-by-one into outer loop

This fixes a bug for dimension 1.