fix matrix to rotate function