refactor wide string handling