More improvements to speed up PD code.