added code to handle utf-8 characters properly