This is the final version of the cachematrix functions