Fixed the algorithm for finding best P C