new version of ppn.py with a factorised code