Bidi: fixed Bidi support and added unit tests