modified cachematrix function