Python 3 fixes

These changes make the develop branch work on Python 3.3+.