refactoring of python scripts