I am not certain I understand all of this because I haven't got into the source and the algo.
But what is the problem with the source?
Isn't it just a programming error that x-h is negative so it should be fixed upfront?
if you're asking if negative input is legal, yes it is.
To simplify it, it's similar to how modulo operates in C.
If you do:
int x = (1-3) % 5; // -2 % 5
you'll get "-2" as a result, but what you're actually
interested in is:
int x = (1-3 + group_order) % 5; // (-2 + 5) % 5 = 3 % 5 == 5
group_order == 5, and you'll get 3 as a result...