fix matrix layout