perforator.py: numerous bugfixes