Don't use str(), use unicode().
Core reformatting to fix PEP8 errors.

Mostly removed unused imports and fixed indentation.