implemented cachematrix functions