Fixed: UnicodeEncodeError error
- Replaced all unsafe str() cast to unicode()
- Refactored various functions to produce unicode strings