Compatibility fixes for Python 3