debugged some of it. Now it does not crash and it works for the trivial case when the p_pdf == q_pdf