Implementation of cachematrix