imported patches and abstractions from old netpd and adapted for netpd2