Replaced 'xrange' by 'range' to maintain Python 3.x compatibility.