Fixed Python 3 compatibility issue (dict.iteritems didn't exist)