pa pd algorithm done (no unit-test yet)