moved cDerivative to its own function