modified code for cachematrix.r