cache functions with comments
fixt the resetting of inv when matrix is set newly