Fix some issues with Python 3 support