Fix a bug in the bidi algorithm