add cost function(untested)