fix matrix copy to buffer