perforator.py: some refactoring