Completed the cachmatrix functions