Fixed some Python2/3 compatibility issues