If you wrap the code in this Discourse post in backticks it will display as a code block, which will make it easier for us to read and understand.
It looks like you define M inside of a function. In that case you’re returning the contents of M, not the name itself.
Are you supposed to pass in a matrix or the function that returns the matrix?