works for square matrix