working cachematrix code