Started implementing pa algorithm