refactor p1 to make it more readable