Handle flipping with matrix.