clean up code, single PIcritval function