changed range with xrange for speedup