added implementation of cachematrix