Code was working for Ascii characters, but not for Unicode values > 128. More careful prescription of utf-8 used in code