fixed write-matrices