PdeUtil: better edge case handling

Also some performance improvements added and a little test code hatched