Fix illegal memory access
More PD-support fixes