finished cachematrix implementation