implemented most of p1