I have a simpleish bit of code here that always seems to give me an error, and i can't figure out quite why.
modulo takes the sign of the dividend: http://en.wikipedia.org/wiki/Modulo_operation#Common_pitfalls
It works with length because you introduce a signed -> unsigned conversion.