Code improvements

Change range to xrange, list comprehension for returns, use enumerate
for looping