fixed write matrices