modify to compitable for python 2 and 3
modify xrange to compatible for python3