refactored allP and allH so it is nice and dry