adding matrix to stop a recursion