Python 3 compat

I've made some changes so it's compatible with Py3.
The tests are passing.

Dicts are using `.items` rather than `.iteritems` which means no generators for Py2, however this should not really be an issue as the collections are probably not massive.