handle utf8 strings and small refactor @coryvirok