Moved the tensor permutation code back into Tensor.