Better solution to p1, and a solution to p2