Fix invert matches

Not ready. At least there's a test case now so this should never break again once it is fixed.