completed cachematrix.R script