Revert CostTable algorithm, will re-write