completed cachematrix.R function