Implement cachematrix functions