new cost function
new cost function2