Improve support for Python 3

All tests pass with versions 3.4 and 2.7.6