Updated cost_matrix to be optimized for indexspaces