calculation seems wrong. count_ps should be computed outside this for loop, right?