PI calculation fix