BiDi support

Hi, please review. I tried following the coding standard.