Fully commented function

Tested with 2x2 and 3x3 matrices.