CWB's version of cachematrix.R