Compatibility fixes for Python3