cost function defined.