refactored computation of p-values and homgeneous statistics