fix some bugs and add utf8 support