fixed CP function producing NAs
by filtering for NAs in input values