Fix bugs related to attempts to inverse matrices without checking for det != 0.