Use string_types to work in both python 2&3
Avoid syntax error in Python 3
Use items() in Python3 and iteritems() in Python2