Fixed issue with calculation of p(w)