implement cachematrix functions