optimization, changed range to xrange