fixed canonicalization for X in read-matrices and write-matrices