edited and completed cachematrix.R