replace str with unicode where necessary. fixes #662