full implementation of p1