Dph optimization

Optimized DPH code.
If your looking at this further, I notice below that you could incorporate `factor` into `lower_bound` and then replace `factor` with a new constant which includes the wqf.