Use .items(), not .iteritems() as latter no longer used in Py3.
Use range instead of xrange for Py3 compat