Added cost function