Replace range with xrange in some places.