implement cachematrix script