Replaced range() with xrange()

It should be ported to py3, but in the mean time this will have to do.