new script pagi.py and some small fixes