break out entire pd calc into function