@jreback this line here was calling mod(x, y) when it should be mod(y, x) that's why it was appearing commutative