cost function improved