Added checks for square matrix