Bug fixes for UTF-8 compatibility