Changes to support Python 3

- use str instead of unicode for py3
- use dict.items instead of dict.iteritems for py3