Fixed an encoding bug
Increased python2/python3 compatibility