Finalized p1 code, added early p2 code