refactor p2m