updating one routine with correct cost function