cleaned up the P and PD code