ADded the cost function