refactoring to upstream-python3