better contraction algo