rewrite Matrix2D, bugs partially fixed.