finalized cachematrix.R