Right, which is why I used the "mod" function which I have in a bunch of places in the code. It's defined as

    function mod(a, b) {
        return ((a % b) + b) % b
    }

And hence is the "proper" mod that you almost always want.

You could make a "wrap" function if you use this functionality a lot and feel that it is clearer, but it's not really deserving of a helper function, since it's quite specialized (at least in the current code).