my version of cachematrix function