added stuff back to costfunc