finished code for p1