* syntax cleanup according to conventions of course
* removed debug output
* fixed bug that the first found SAP was used and not the minimal
* code reduction