Refactor range to xrange