updated code for cachematrix