fixed the cost function