Wrote PAA routine - not tested yet