implemented better contraction and squeeze/sort algos