Improve compatibility with Python 3