Py3k fixes

s/xrange/range/. Convert to int. 

Makes it work on Python3.