cleaned up and fixed DPD handling code