Refactored code to be more rigorous Unicode-wise.