Prevent UnicodeEncodeError: 'ascii' codec can't encode characters in position ...: ordinal not in range(128)
Encode to utf-8 only when needed
Added an space between code and comments in order to follow the coding standars