modified version of cachematrix.R