More reordering and use === consistently
Only compute p.toList once