Refactor p function to use the e function