encoder: implement proper string encoding