replace xrange with range for python3 compatibility