use detailed cost function