python scripts: refactoring