Improve support for Python 3