my implementation of cachematrix