only square matrix once in recursion