Implemented the cachematrix functions for the assignment