Document the cost function