Fixed compatibility with python3 (but may break on python2 because of str/unicode junk)