Added functions to turn a matrix.