fix matrix formatting