Added check for square matrix.