the xrange is slowing down the cython code.  Use range instead.