Updated code for cachematrix