properly encode unicode to utf-8