Cost function refined