modifed monoid string encoding