Check for IndexError

It's happened to me on a laptop, where the trackpad has probably been detected as a joystick interface. The error becomes very annoying.
I'm not sure if this check is enough to silence it, but I think we should check that `b` isn't out of range anyway.