changed xrange to range for compatibility with Python 3