fix up unicode support and refactor things a little