completed the cachematrix function, with comments