updated cachematrix function