changes to syntax (mostly) for python3 compatibility (in theory)
Working version with Python2 and Python3