This calculation seems wrong to me. Won't this reset count_ps on every loop iteration?