Python 3 compatibility, use next method to get next item from generator
Replaced final instances of dict.iteritems with six.iteritems wrapper, fixed made  Token sortable
Fixed missing code block from a bad merge