cachematrix.R edited to match requirements