use range instead of xrange for Python3 compatibility.