Corrected best cost code
Use of slices to avoid copying data.