Complete cachematrix code with comments